Date/Time functions (MOPS)

$dateTimeFormatter()

Signature: $dateTimeFormatter(date, [format], [timeZone])

Formats date/time values and handles time zone conversions. Supports ISO 8601 standards, UTC formatting, and custom time zone offsets.

Skipping both format and time zone will default the formatter to the settings of the browser.

Time zone is written as +/-hhmm. For using Time zone, the timestamp has to be in ISO format to work properly.

To skip format, use null or ''


Parameters

Parameter Type Description
date string|number Valid ISO 8601 date string or timestamp (e.g., "2023-09-15T14:30:00.000Z")
format string (optional) date-fns format pattern or special keyword ("ISO" or "UTC"). Default: locale’s short date + time format
timeZone string (optional) Time zone offset in ±hhmm format (e.g., "+0530") or "UTC"

Examples

  • Basic Formatting

    $dateTimeFormatter("2023-09-15T14:30:00.000Z", "yyyy-MM-dd HH:mm") => "2023-09-15 14:30"
    
  • Time Zone Conversion

    $dateTimeFormatter("2023-09-15T14:30:00.000Z", "h:mm a", "+0500") => "7:30 PM" (Original UTC+0 converted to UTC+5)
    
  • ISO Format

    $dateTimeFormatter(1694788200000, "ISO") => "2023-09-15T14:30:00.000Z"
    
  • UTC Formatting

    $dateTimeFormatter("2023-09-15", "UTC") => "Sep 15, 2023, 12:00:00 AM"
    
  • Error Examples

    $dateTimeFormatter("September 15", "", "+1300") => "Time zone can only be utilised with date time in ISO standard format..."
    
    $dateTimeFormatter("2023-09-15", "HH:mm", "+1500") => "Hours in time zone can't exceed (+/-) 12 hours"
    

$dateTimeLocalizer()

Signature: $dateTimeLocalizer(date, [locale], [timeZone])

Formats dates/times for specific locales/timezones. Handles ISO/UTC formats and custom timezone offsets.

Skipping both locale and time zone will default the formatter to the settings of the browser.

Locale is defined by the BCP 47, i.e. en-US, se-SV. If set to ISO, it will return ISO formatted date string.

Time zone is written as +/-hhmm or with IANA time zone names. For using Timezone, the timestamp has to be in ISO format to work properly.

To skip locale, type null or ''

Parameters

Parameter Type Description
date string|number Valid ISO 8601 date string or timestamp
locale string (optional) BCP 47 language tag (e.g., "fr-FR") or special keywords ("ISO", "UTC")
timeZone string (optional) IANA timezone name (e.g., "America/New_York") or ±hhmm offset

Examples

  • Basic localization

    $dateTimeLocalizer("2023-09-15T14:30:00.000Z", "fr-FR")  => "15/09/2023 14:30:00"
    
  • Timezone conversion

    $dateTimeLocalizer("2023-09-15T14:30:00.000Z", "en-US", "Asia/Tokyo") => "9/16/23 11:30:00 AM"
    
  • Offset adjustment

    $dateTimeLocalizer("2023-09-15T14:30:00.000Z", "de-DE", "+0200") => "15.09.23 16:30:00"