15. Date¶
15.1. Paths¶
/etc/timezone
/etc/localtime
15.2. Date Formatting¶
Directive |
Example |
Meaning |
---|---|---|
|
Sun, Mon, ..., Sat |
Weekday as locale's abbreviated name |
|
Sunday, Monday, ..., Saturday (en_US) |
Weekday as locale's full name |
|
0, 1, ..., 6 |
Weekday as a decimal number, where 0 is Sunday and 6 is Saturday |
|
01, 02, ..., 31 |
Day of the month as a zero-padded decimal number |
|
Jan, Feb, ..., Dec (en_US) |
Month as locale's abbreviated name |
|
January, February, ..., December (en_US) |
Month as locale's full name |
|
01, 02, ..., 12 |
Month as a zero-padded decimal number |
|
00, 01, ..., 99 |
Year without century as a zero-padded decimal number |
|
0001, 0002, ..., 2013, 2014, ..., 9998, 9999 |
Year with century as a decimal number |
|
00, 01, ..., 23 |
Hour (24-hour clock) as a zero-padded decimal number |
|
01, 02, ..., 12 |
Hour (12-hour clock) as a zero-padded decimal number |
|
AM, PM (en_US) |
Locale's equivalent of either AM or PM |
|
00, 01, ..., 59 |
Minute as a zero-padded decimal number |
|
00, 01, ..., 59 |
Second as a zero-padded decimal number |
|
000000, 000001, ..., 999999 |
Microsecond as a decimal number, zero-padded on the left |
|
(empty), +0000, -0400, +1030 |
UTC offset in the form +HHMM or -HHMM (empty string if the object is naive) |
|
(empty), UTC, EST, CST |
Time zone name (empty string if the object is naive) |
|
001, 002, ..., 366 |
Day of the year as a zero-padded decimal number |
|
00, 01, ..., 53 |
Week number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0 |
|
00, 01, ..., 53 |
Week number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0 |
|
Tue Aug 16 21:30:00 1988 (en_US) |
Locale's appropriate date and time representation |
|
08/16/1988 (en_US); 16.08.1988 (de_DE) |
Locale's appropriate date representation |
|
21:30:00 |
Locale's appropriate time representation |
|
% |
A literal |
|
0001, 0002, ..., 2013, 2014, ..., 9998, 9999 |
ISO 8601 year with century representing the year that contains the greater part of the ISO week ( |
|
1, 2, ..., 7 |
ISO 8601 weekday as a decimal number where 1 is Monday |
|
01, 02, ..., 53 |
ISO 8601 week as a decimal number with Monday as the first day of the week. Week 01 is the week containing Jan 4 |
Meaning |
With |
Without |
---|---|---|
day |
|
|
hour 24h |
|
|
hour 12h |
|
|
day of a year |
|
|
month |
|
|
minute |
|
|
second |
|
|
week number (Sunday first) |
|
|
week number (Monday first) |
|
|
weekday (Sunday first) |
|
|
year short |
|
|
year long |
|
|
15.3. Date¶
$ date -I
1969-07-21
$ date -Iseconds
1969-07-21T02:56:15+00:00
$ date +"%F %H:%M:%S %Z"
1969-07-21 02:56:15 UTC
$ date +%s
1234567890
$ date -d @1234567890
Sat Feb 14 00:31:30 CET 2009
$ date -u
Mon Jul 21 02:56:15 UTC 1969
$ date -d '-10 min'
Mon Jul 21 02:46:15 UTC 1969
$ TZ=UTC date
Mon Jul 21 02:56:15 UTC 1969
$ TZ=CET date
Mon Jul 21 04:56:15 CEST 1969
$ TZ=GMT date
Mon Jul 21 02:56:15 GMT 1969
15.4. Unix Timestamp¶
Seconds since midnight of January 1st, 1970 (1970-01-01 00:00:00 UTC)
Unix era, also known as "epoch"
In most systems represented as 32-bit integer
Max value is 2,147,483,647 (2038-01-19 03:14:07 UTC)
Min value is -2,147,483,647 (1902-12-13 20:45:53 UTC)
If you add 1 to max value, you will get overflow to min value
Linux kernel 5.6 (released 29 March 2020) has a fix for this problem so that 32-bit systems can run beyond the year 2038
https://lore.kernel.org/lkml/CAHk-=wi9ZT7Stg-uSpX0UWQzam6OP9Jzz6Xu1CkYu1cicpD5OA@mail.gmail.com/
$ TZ=UTC date +%s
1234567890
$ TZ=CET date +%s
1234567890
$ TZ=GMT date +%s
1234567890
15.5. Commands¶
tzconfig
-tzselect
- view timezonestzselect
- select a timezonedate
- print or set the system date and timedate +%F
-date --iso-8601
date -Ins
date -I
- ISO 8601 (YYY-MM-DD)date -Iseconds
date +%s
- timestamp, seconds since: 1970-01-01T00:00:00.000000+00:00date -d @1234567890
date --date='-90 minute' -Iseconds
date --date='-10 min'
-