Custom Display Format for Date/Time
Frequently used format rules for date/time display
Rule | Display | |
---|---|---|
Year | YY | 70 71 ... 29 30 (last two digits of the year) |
YYYY | 1970 1971 ... 2029 2030 | |
Month | M | 1 2 ... 11 12 |
MM | 01 02 ... 11 12 (Number less than 10 is preceded by 0) | |
MMM | Jan Feb…Nov Dec | |
MMMM | January Febrary…November December | |
Day | D | 1 2 ... 30 31 |
DD | 01 02 ... 30 31 | |
Days in a year | DDD | 1 2 ... 364 365 |
DDDD | 001 002 ... 364 365 | |
Days in a week | d | 0 1 ... 5 6 |
ddd | Sun Mon… Fri Sat | |
dddd | Sunday Monday…Friday Saturday | |
E | 1 2 ... 6 7 | |
Weeks in a year | w | 1 2 ... 52 53 |
ww | 01 02 ... 52 53 | |
Quarter | Q | 1 2 3 4 |
Morning/Afternoon | A | AM PM |
Hour | H | 0 1 ... 22 23 (24-hour system) |
HH | 00 01 ... 22 23 | |
h | 1 2 ... 11 12 (12-hour system) | |
hh | 01 02 ... 11 12 | |
Minute | m | 0 1 ... 58 59 |
mm | 00 01 ... 58 59 | |
Second | s | 0 1 ... 58 59 |
ss | 00 01 ... 58 59 | |
Millisecond | SSS | 001 002 ... 998 999 |
Time Zone | Z | +08:00 |
ZZ | +0800 |
Note: MM and mm are case-sensitive for months and minutes, respectively; other rules are not case-sensitive.
With the rules above and the connectors (-/year, month, day, etc.) you can get the desired format.
Example
Take [2021-09-15 15:09:18] as an example.
Rule | Display |
---|---|
YYYY/MM/DD | 2021/09/15 |
YYYYMMDD | 20210915 |
YYMMDD | 210915 |
YYYYMMDDHHmmss | 20210915150918 |
YYYYMMDD HHmmss | 20210915 150918 |
YYYYMMDDHHmmssSSS | 20210915150918317 |
Have questions about this article? Send us feedback