fd (format date)

The $fd function converts a given date or time into a formatted readable text. A format pattern may be specified as well as a time zone.

Syntax

$fd(date[,format[,timeZone]])

Parameter

Name

Description

date

Any of the following supported date/time types:

  • DateTime (Date with time and time zone)

  • DateRange (Date range. "From" and "To" date will be formatted and printed separately)

  • Number (Timestamp in milliseconds)

  • Time (Time object)

  • Timestamp (Timestamp object)

format
(optional)

An optional format pattern. If not given, the default pattern from the localization will be loaded (lobsterui/dateFormat lobsterui/timeFormat).

The pattern is defined by a placeholder syntax, where each placholder sequence will be replaced by the appropriate date or time values.

e.g. 'yyyy/MM/dd' stands for two digits day, two digits month, four digits year (example result: 2019/12/03).

A list of supported placeholders can be found later in the appropriate chapter of the manual.

timeZone
(optional)

An optional time zone can be defined in which the date is printed. By default the default time zone of the user will be used.

See also: getUserTimezone (Get user time zone).

The time zone can be given as TimeZone object as well as time zone id (e.g. Europe/Berlin).
If possible at all, a Javascript Date can be given from which the time zone is red. This is not possible in any common way.

Return value

Returns the given time as formatted text.

Supported placeholders

Sample value

Monday, 07/04/2005 17:03:05,004

Pattern and sample output (standard EN) per component with sample value as above:

Component

1x

2x

3x

4x

5x

year

Y "05"
YY "05"
YYY "2005"
YYYY "2005"
YYYYY "02005"

quarter

Q "3"
QQ "03"
QQQ "Q3"
QQQQ "third Quarter"

month

M "7"
MM "07"
MMM "Jul"
MMMM "July"

day of week

E "1"
EE "01"
EEE "Mon"
EEEE "Monday"

day (of month)

D "4"

DD "04"

additional pre-zeros (without practical relevance)

hour 1-12

h "5"

hh "05"

additional pre-zeros (without practical relevance)

hour 0-11

K "5"

KK "05"

additional pre-zeros (without practical relevance)

hour 0-23

H "17"

HH "17"

additional pre-zeros (without practical relevance)

hour (AM/PM)

a "AM"

repetitions of 'a' are ignored

minutes

m "3"

mm "03"

additional pre-zeros (without practical relevance)

seconds

s "5"

ss "05"

additional pre-zeros (without practical relevance)

milliseconds

S "4"

SS "04"

SSS "004"

additional pre-zeros (without practical relevance)

►NOTE◄

  • If components (see rows in table above) are addressed more than once within the same pattern, an empty string is returned instead of the whole pattern.

  • There is no option to explicitly declare characters as 'literal' within the pattern, to prevent interpretation. This imposes the following constraints on pattern design:

    • All characters, representing components according to the table above, cannot be used as literals in a pattern. This constraint is handled as case sensitive.

Examples

Negative examples are highlighted red.

Input value

Pattern

Output

Comment/Issue

05/17/2011 17:35:11.050

YYYY-MM-DD HH:mm

2011-05-17 17:35

date/time format suitable for string sorting.

YYYY-MM-DD HH:MM

empty

duplicate reference to component month per MM (as opposed to 'mm' for minutes).

YYYY-MM-DD HH:mm UTC

2011-05-17 17:35 UTC

reference to time zone 'UTC' entered as a literal.

YYYY-MM-DD HH:mm GMT

empty

character 'M' in supposed literal 'GMT' qualifies as a duplicate reference to month (MM).

EEEE HH:mm GMT

Tuesday 17:35 G5T

without a reference to 'MM' (for month) the number of the month ('5') replaces the 'M' character in supposed literal 'GMT'.

05/17/2011 00:35:11.050

hh:mm a

12:35 AM

12-hour time format where the first hour of the AM/PM period reads as '12'.

KK:mm a

00:35 AM

12-hour time format where the first hour of the AM/PM period reads as '0'.

HH:mm:ss.SSS

00:35:11.050

Time format with maximum precision (milliseconds).

HH:mm:ss.S

00:35:11.50

Time format with inappropriate representation the milliseconds.

EEEE, D. MMMM (QQQ)

leer

The supposed literal comma ',' character destroys the syntax of the surrounding expression, as it suggests an additional argument follows after EEEE:
$fd(..., EEEE, D. MMMM (QQQ))

Instead it should be:
$fd(..., EEEE\, D. MMMM (QQQ\))

PARSE(EEEE, D. MMMM {QQQ})

Tuesday, 17. May

The component for quarter is omitted, since the curved brackets inside the PARSE function as interpreted as a reference to an element with 'id' QQQ which might not exist.
Instead the pattern should be: D. MMMM \{QQQ\}

Localization of date format strings

Some patterns resolve strings that may be localized by Localization or Company specific localization.

Component

Pattern

Bundle name

Resource name

EN (Standard)

DE (Standard)

quarter

QQQQ

lobsterui

quarterNames

first quarter,second quarter,third quarter,fourth quarter

erstes Quartal,zweites Quartal,drittes Quartal,viertes Quartal

month

MMMM

lobsterui

month.names

January,February,March, ...

Januar,Februar,März, ...

MMM

lobsterui

month.namesShort

Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec

Jan,Feb,Mrz,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez

day of week

EEEE

lobsterui

dayNames

Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday

Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag

EEE

lobsterui

dayNamesShort

Sun,Mon,Tue,Wed,Thu,Fri,Sat

So,Mo,Di,Mi,Do,Fr,Sa

hour (AM/PM)

a

lobsterui

am

AM

vorm.

pm

PM

nachm.