Skip to content

Format signs

Format and ParseByFormat methods are not completely reversible. Format method supports all of the following signs, while ParseByFormat method does not support K, W, N, L, w, t, o, q, c because these signs are custom and do not have corresponding signs in the standard time package.

signdesclengthrangeexample
dDay of the month, padded to 2201-3102
DDay of the week, as an abbreviate localized string3Mon-SunMon
jDay of the month, no padding-1-312
KEnglish ordinal suffix for the day of the month, 2 characters. Eg: st, nd, rd or th. Works well with j2st/nd/rd/thth
lDay of the week, as an unabbreviated localized string-Monday-SundayMonday
FMonth as an unabbreviated localized string-January-DecemberJanuary
mMonth, padded to 2201-1201
MMonth as an abbreviated localized string3Jan-DecJan
nMonth, no padding-1-121
YFour-digit year40000-99992006
yTwo-digit year200-9906
aLowercase morning or afternoon sign2am/pmpm
AUppercase morning or afternoon sign2AM/PMPM
gHour in 12-hour format, no padding-1-123
GHour in 24-hour format, no padding-0-2315
hHour in 12-hour format, padded to 2200-1103
HHour in 24-hour format, padded to 2200-2315
iMinute, padded to 2201-5904
sSecond, padded to 2201-5905
ODifference to Greenwich time (GMT) without colon between hours and minutes---0700
PDifference to Greenwich time (GMT) with colon between hours and minutes---07:00
ZZone name--MST
Wweek of the year-1-521
Nday of the week11-72
LWhether it's a leap year10-10
SUnix timestamp with second--1596604455
UUnix timestamp with millisecond precision--1596604455666
VUnix timestamp with microsecond precision--1596604455666666
XUnix timestamp with nanosecond precision--1596604455666666666
uMillisecond-1-999999
vMicrosecond-1-999999999999
xNanosecond-1-999999999999999999
wDay of the week10-61
tTotal days of the month228-3131
zTime zone--Asia/Shanghai
oTime offset--28800
qQuarter11-41
cCentury-0-9921

Released under the MIT License, unauthorized reproduction is prohibited in any form