todo
![]() |
The Linux command.
See also:
Usage ∞
yyyy-mm-dd
∞
date +%Y-%m-%d
yyyy-mm-dd_hh-mm
∞
date --utc +'%Y-%m-%d_%H-%M'
This uses 24-hour time and UTC to maintain sortability and avoid timezone confusion.
Maybe you prefer something which isn't a colon (:
) but looks like a colon
date --utc +'%Y-%m-%d_%H꞉%M'
Timezone Conversion ∞
props to http://www.wiki.balug.org/wiki/doku.php?id=balug:covid-19
On any system with GNU date(1), included in GNU coreutils, you can convert a remote event's time/date to your local timezone's time/date using syntax as per the following example:
date -d 'TZ="Europe/London" 2021-02-13 14:00'
Sat Feb 13 06:00:00 PST 2021
GNU date(1) will use your system's TZ database to convert time/date correctly, including compensating for DST / Standard Time issues at either your and/or the remote location.
It is also possible to generalize that syntax, to convert to a timezone differing from your local timezone, by prefacing the foregoing command with an output-timezone qualifier, e.g., as follows requesting conversion to Arizona time/date:
TZ='America/Phoenix' date -d 'TZ="Europe/London" 2021-02-13 14:00'
Sat Feb 13 07:00:00 MST 2021
Quoting must be as shown, and timezone names must be correct, or you will get errors or (worse) silent ignoring of the provided timezone qualifier.
Use canonical TZ database names.
Why you don't use a short name
Do not use the familiar 3- or 4-letter shortcut names like
PST
and PDT
, as they are neither unique nor standardised – nor UTC offsets like UTC-8
, which for many locations have DST vs. Standard Time problems: The short names' ambiguities become more troubling the more international one's focus is. For example:
-
CST
can mean:- China Standard Time (
UTC+8
) - Cuba Standard Time (
UTC−5
) - (North American) Central Standard Time (
UTC−6
) - .. and it is also a variant name for
ACST
(Australian Central Standard Time,UTC+9:30
)
- China Standard Time (
Likewise, a time zone's short name will differ depending on language, as with:
WET
(Western European Time,UTC+0
)WEZ
(Westeuropäische Zeit) in GermanHEO
(Heure d'Europe occidentale) in FrenchZEČ
(Západoevropský čas) in Czech-
ΏΔΕ
(Ώρα Δυτικής Ευρώπης) in Greek.
Thus the short names' deprecated status.
On MacOS ∞
(macOS)
MacOS uses BSD's date(1) which lacks the -d
option.
Homebrew will supply gdate
brew install coreutils
On Windows ∞
(Windows)
Windows Subsystem for Linux 2 has the appropriate date
. It is likely that Windows Subsystem for Linux does too.
Otherwise, install GnuWin32 for date
.
Web ∞
Resources ∞
Times
#!/bin/sh for tz in \ 'PST8PDT US/Pacific' \ 'CST6CDT US/Central' \ GMT0 \ do TZ="$(set -- $tz; printf '%s\n' "$1")" printf '%s\n' "$(TZ="$TZ" date -Iseconds "$@") $(TZ="$TZ" date "$@") $tz" done | sort -u # 'EST5EDT US/Eastern' \ # Europe/London \ # Asia/Kolkata # (for TZ in $(cd /usr/share/zoneinfo && find * -follow -type f -exec file -L \{\} \; | sed -ne 's;^\([^:]*\): timezone data,.*$;\1;p'); do export TZ; date -d @1707350400 | tr '\012' ' '; echo "$TZ"; done) | sort -k 3,3bn -k 4,4
Last updated 2024-03-09 at 23:17:59
noting timezone conversion for reference