Difference between revisions of "Time and date specification"
Jump to navigation
Jump to search
(Created page with "Time and date formats are specified with the following expressions. This is useful to read or write files with custom time and date format. See for instance the documentation...") |
|||
Line 4: | Line 4: | ||
! Expression | ! Expression | ||
! Comments | ! Comments | ||
+ | |- | ||
+ | |C | ||
+ | |'C' locale is considered for numbers (dot for decimal separation and omit group separators) | ||
+ | |- | ||
+ | |D | ||
+ | |For input only, unspecified fields of the format are silently ignored and set to their default values. | ||
|- | |- | ||
|d | |d |
Revision as of 13:38, 21 November 2022
Time and date formats are specified with the following expressions. This is useful to read or write files with custom time and date format. See for instance the documentation of gptime and Custom ASCII formats.
Expression | Comments |
---|---|
C | 'C' locale is considered for numbers (dot for decimal separation and omit group separators) |
D | For input only, unspecified fields of the format are silently ignored and set to their default values. |
d | The day as number without a leading zero (1 to 31) |
dd | The day as number with a leading zero (01 to 31) |
ddd | The abbreviated localized day name (e.g. 'Mon' to 'Sun') |
dddd | The long localized day name (e.g. 'Monday' to 'Sunday') |
M | The month as number without a leading zero (1-12) |
MM | The month as number with a leading zero (01-12) |
MMM | The abbreviated localized month name (e.g. 'Jan' to 'Dec') |
MMMM | The long localized month name (e.g. 'January' to 'December') |
yy | The year as two digit number (00-99) |
yyyy | The year as four digit number |
h | The hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) |
hh | The hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) |
H | The hour without a leading zero (0 to 12) |
HH | The hour with a leading zero (00 to 12) |
m | The minute without a leading zero (0 to 59) |
mm | The minute with a leading zero (00 to 59) |
s | The second without a leading zero (0 to 59) |
ss | The second with a leading zero (00 to 59) |
sz | The second including fraction of seconds (0 to 60, excluding 60) |
ssz | The second including fraction of seconds (00 to 60, excluding 60) |
z | The milliseconds without leading zeroes (0 to 999) |
zzz | The milliseconds with leading zeroes (000 to 999) |
AP | Interpret as an AM/PM time. AP must be either "AM" or "PM". |
ap | Interpret as an AM/PM time. ap must be either "am" or "pm". |
' | Any text inside single quotes is considered as a regular expression. |
Any text even outside quotes is considered verbatim if it does not match one of the above expressions. In general, to match extra characters, it is safer to put them inside single quotes.
Examples
For input format
Input text | Format | Date time value |
---|---|---|
11 PM | H AP | 1970-01-01 23:00:00.000000 |
11 pm | H ap | 1970-01-01 23:00:00.000000 |
11 | H | 1970-01-01 11:00:00.000000 |
23 | H | expected a number between 0 and 12: '23' |
23 | h | 1970-01-01 23:00:00.000000 |
23 am | h ap | expected a number between 1 and 12: '23' |
11:10:08.345 | h:m:s | 1970-01-01 11:10:08.000000 |
11:10:08.345 | h:m:ss | 1970-01-01 11:10:08.000000 |
11:10:08.345 | h:m:sz | 1970-01-01 11:10:08.345000 |
11:10:08.345 | h:m:ssz | 1970-01-01 11:10:08.345000 |
It's 11:10 am | 'It.s +'h:m ap | 1970-01-01 11:10:00.000000 |
11:10 UTC | h:m UTC | 1970-01-01 11:10:00.000000 |
11:10 apéro | h:m apéro | expected am or pm: 'ap' |
11:10 apéro | h:m | unmatched characters: ' apéro' |
For ouput format
Date time value | Format | Output |
---|---|---|
1970-01-01 23:00:00.000000 | H AP | 11 PM |
1970-01-01 23:00:00.000000 | h ap | 23 pm |
1970-01-01 11:10:08.345000 | h:m:s | 11:10:8 |
1970-01-01 11:10:08.345000 | h:mm:s | 11:10:08 |
1970-01-01 11:10:08.345000 | hh:mm:sz | 11:10:8.345000 |
1970-01-01 11:10:08.345000 | hh:mm:ssz | 11:10:08.345000 |
1970-01-01 11:10:08.345000 | hh:mm:ssz UTC | 11:10:08.345000 UTC |