Aller au contenu principal
Version: v20 R4

Date and Time Formats

Throughout your 4D projects, you might need to format date and/or time values according to the specificities of the application, the platform, or the interface.

4D includes a comprehensive list of patterns that you can use to create and apply customized date and time formats in your applications, in addition to default formats. Customized format patterns are supported by the following features:

Pattern list

The following table lists all supported patterns for date and time formats.

SymbolMeaningPatternExample Output
Gera designatorG, GG, or GGGAD
GGGGAnno Domini
GGGGGA
yyearyy96
y or yyyy1996
Yyear of "Week of Year"Y1997
uextended yearu4601
QquarterQ2
QQ02
QQQQ2
QQQQ2nd quarter
QQQQQ2
qstand-alone quarterq2
qq02
qqqQ2
qqqq2nd quarter
qqqqq2
Mmonth in yearM9
MM09
MMMSep
MMMMSeptember
MMMMMS
Lstand-alone month in yearL9
LL09
LLLSep
LLLLSeptember
LLLLLS
wweek of yearw27
ww27
dday in monthd2
dd2
Dday of yearD189
Eday of weekE, EE, or EEETue
EEEETuesday
EEEEET
EEEEEETu
elocal day of weeke2
ee02
eeeTue
eeeeTuesday
eeeeeT
eeeeeeTu
cstand-alone local day of weekc or cc2
cccTue
ccccTuesday
cccccT
ccccccTu
aAM or PMa, aa, or aaaPM [abbrev]
aaaaPM [wide]
aaaaap
bAM, PM, noon, midnightb, bb, or bbbmid.
bbbbmidnight
bbbbbmd
Bflexible day periodsB, BB, or BBBat night [abbrev]
BBBBat night [wide]
BBBBBat night [narrow]
hhour in am/pm (1~12)h7
hh07
Hhour in day (0~23)H0
HH00
Khour in am/pm (0~11)K0
KK00
khour in day (1~24)k24
kk24
mminute in hourm4
mm04
ssecond in minutes5
ss05
XTime Zone: ISO8601 basic hm?, with Z for 0X-08, +0530, Z
Time Zone: ISO8601 basic hm, with ZXX-0800, Z
Time Zone: ISO8601 extended hm, with ZXXX-08:00, Z
Time Zone: ISO8601 basic hms?, with ZXXXX-0800, -075258, Z
Time Zone: ISO8601 extended hms?, with ZXXXXX-08:00, -07:52:58, Z
xTime Zone: ISO8601 basic hm?, without Z for 0x-08, +0530
Time Zone: ISO8601 basic hm, without Zxx-800
Time Zone: ISO8601 extended hm, without Zxxx-08:00
Time Zone: ISO8601 basic hms?, without Zxxxx-0800, -075258
Time Zone: ISO8601 extended hms?, without Zxxxxx-08:00, -07:52:58
OTime Zone: short localized GMTOGMT-8
Time Zone: long localized GMT (=ZZZZ)OOOOGMT-08:00
zTime Zone: specific non-locationz, zz, or zzz-0800
zzzzGMT-08:00
zzzzz-08:00, -07:52:58, Z
'escape for text''
' 'two single quotes produce one' '' '

Exploring patterns

y vs Y

y is the calendar year, while Y is the year based on the week number. For example, if the first days of January 2010 are not week #1, then y = 2010 but Y = 2009 (until the date where the 1st week of 2010 begins).

L (stand-alone) vs M

In some languages (Russian, Slovak), the month used alone is different from the month in a date. In "January 10, 2010", "January" is not spelled the same as in "rendez-vous in January".

e vs c

Same remark as for L and M: c is for a day used alone "every tuesday") and e is for a day in a date ("Tuesday January 15, 1951").

E vs e

e is based on system settings: if the week is defined in the system as starting on a Wednesday, then Wednesday will have the numerical value "1" (or zero) whereas "E" always returns the same value (from 1 to 7 or from 0 to 6).

Leading zeros

In general, when the number of letters in the formatting string is higher than the expected number, leading zeros are added. Ex: "yyyyyy" would give "001996".

Localized parts

Some parts of the outputs, such as "midnight" or "Tuesday" are localized, according to regional settings.

For example, for the time 13:25:34, "B" will display in the afternoon on an US system, and après-midi on a French system.

Extra letters

Formatting strings can contain characters not to be interpreted as formatting characters: if they are between "a" and "z" or "A" and "Z", they must be enclosed in single quotes.

Par exemple :

"15:30:00" with pattern "HH 'hours and' mm 'minutes'" produces "15 hours and 30 minutes".

Starting and ending spaces

Starting and ending spaces in patterns are automatically trimmed in outputs. If you want to add spaces before or after the resulting string, you must enclose them in single quotes.

Par exemple :

" HH : mm : ss " ---> "09 : 10 : 25" "' 'HH : mm : ss' '" ---> " 09 : 10 : 25 "

Exemples

Date or timePatternRésultatCommentaires
15/06/2000"QQQQ""2nd quarter"localized
17/03/2001"D""76"76th day of the year
17/03/1954"w""11"11th week of the year
17/03/1954"eeee""Wednesday"localized
15:00:00"a""PM"
18:00:00"K a""6 PM"
13:30:15"hh:mm aa O""01:30 PM GMT+1"

Voir également

See this blogpost for more information on the custom date and time formats.