Skip to content

Date and time format patterns

Include: Use System\Locale.pkg

See Also: Locale attributes

Purpose

Date and time format patterns define the tokens used by DF_LOCALE_DATE_FORMAT, DF_LOCALE_TIME_FORMAT, DF_LOCALE_DATETIME_FORMAT, and DF_LOCALE_TIMESPAN_FORMAT.

Tokens

Token Output Notes
\x Next character literally For example, G\MT produces GMT.
y Year since age No zero-padding.
yy Two-digit year since age Zero-padded to two digits.
yyyy Full year Three or more y characters write the full year.
M Numeric month No zero-padding.
MM Two-digit month Zero-padded to two digits.
MMM Short month name Uses DF_LOCALE_SHORT_MONTH1 through DF_LOCALE_SHORT_MONTH12.
MMMM Long month name Uses DF_LOCALE_LONG_MONTH1 through DF_LOCALE_LONG_MONTH12.
d Numeric day No zero-padding.
dd Two-digit day Zero-padded to two digits.
ddd Short day name Uses DF_LOCALE_SHORT_DAY1 through DF_LOCALE_SHORT_DAY7.
dddd Long day name Uses DF_LOCALE_LONG_DAY1 through DF_LOCALE_LONG_DAY7.
h 12-hour hour No zero-padding.
hh 12-hour hour Zero-padded to two digits.
H 24-hour hour No zero-padding.
HH 24-hour hour Zero-padded to two digits.
m Minute No zero-padding.
mm Minute Zero-padded to two digits.
s Second No zero-padding.
ss Second Zero-padded to two digits.
S Millisecond No zero-padding.
SS Millisecond Zero-padded to two digits.
t First character of AM/PM text Uses DF_LOCALE_AM_STRING or DF_LOCALE_PM_STRING.
tt Full AM/PM text Uses DF_LOCALE_AM_STRING or DF_LOCALE_PM_STRING.
z GMT-prefixed UTC offset in hours Example output: GMT+0.
zzzz GMT-prefixed UTC offset in HH:00 form Example output: GMT+00:00.
Z Numeric UTC offset Example output: +0000.
ZZZZ GMT-prefixed UTC offset in HH:00 form Example output: GMT+00:00.
Any other character Literal text Repeated literal characters are written as repeated text.

Example

Use System\Locale.pkg

DateTime dDate
String sDate

Push_Locale
Set_Attribute DF_LOCALE_UTC_OFFSET to 0
Set_Attribute DF_LOCALE_DATETIME_FORMAT to "ddd, dd MMM yyyy HH:mm:ss G\MT"
Move "Thu, 15 Feb 2024 08:35:04 GMT" to dDate
Move dDate to sDate
Pop_Locale