Skip to main content

Datetime Formatting

Dromo's date, datetime, and time field types are deeply customizable, both in the format that is displayed to the user, and in the format provided in the result JSON. All three of these types share the same configuration options.

Format strings

Both the displayFormat and outputFormat options accept format strings allowing you to exactly specify how the value should appear to the user and/or appear in the results.

Under the hood, these format strings are powered by the Luxon library. You can find the full reference for how to write format strings in the Luxon docs here.

In addition, Dromo provides the special format string "[ISO]", which will output the value in the ISO-8601 format appropriate to the field type.

The default displayFormats that Dromo uses are:

Field typedisplayFormat
Date"D"
Datetime"f"
Datetime
withSeconds: true
"F"
Time"t"
Time
withSeconds: true
"tt"

The default outputFormat for all types is "[ISO]". For the Datetime and Time types, this will not include a time zone offset. Seconds will also not be included, unless withSeconds: true is supplied with the field options.

Locale

Many of the formatting options available, including Dromo's displayFormat defaults, are dependent on the field's locale.

This will affect things like ordering of date fields, names of weekdays and months, the alphabet used, and the calendar.

Dromo defaults to the "en-US" locale.

The ISO-8601 format is locale-independent, but if you specify a custom outputFormat, this will be affected by the field's locale.

Configuration example

Here is an example of a complex datetime configuration:

{
label: "Saved at",
key: "savedAt",
type: [
"datetime",
{
locale: "de-DE",
displayFormat: "EEE MMM d, y, H:mm:ss",
withSeconds: true
}
]
}

Time zones

By default, Dromo datetime types are time zone agnostic. Dromo does not show or output any time zone information.

If you wish to import times including time zones, you can specify a displayFormat and outputFormat which contain time zone offset information. When parsing datetimes without time zone offsets, UTC is assumed.

Unix timestamp

For the Date and Datetime times, you can configure Dromo to output a Unix timestamp with the format strings "X" (in seconds) and "x" (in milliseconds). If used as an output format, these values will be output as numbers instead of strings.