Skip to content

Instantly share code, notes, and snippets.

@robla
Last active July 9, 2021 22:28
Show Gist options
  • Save robla/3f4ac1e5418a18cb2b902c55b9c467bc to your computer and use it in GitHub Desktop.
Save robla/3f4ac1e5418a18cb2b902c55b9c467bc to your computer and use it in GitHub Desktop.
#!/bin/bash
function print_24hr_string () {
# Wrapper around "date" command for printing 24hr datetime
# 1: "tzolson": timezone id from the Olson DB
tzolson="$1"
# 2: "placename": more relevant timezone label than Olson's choices
placename="$2"
# 3: "fdate" is "function date" for date passed to this func
fdate="$3"
isodate=$(TZ="$tzolson" date --date="${fdate}" -Im)
datefmt="* ${isodate}: %a %_d %B %Y %_I:%M%P %Z (${placename}; %-:::z UTC)"
TZ="$tzolson" date --date="${fdate}" +"${datefmt}"
}
#MAIN
# "sdate" is "script date"
if [ -z "$1" ]; then
# if $1 is not given on command line, use current UTC time
sdate="$(date -u)"
else
sdate="$1"
fi
print_24hr_string "Europe/Amsterdam" "Amsterdam" "${sdate}"
print_24hr_string "Europe/London" "London" "${sdate}"
print_24hr_string "UTC" "UTC" "${sdate}"
print_24hr_string "America/New_York" "New York" "${sdate}"
print_24hr_string "America/Los_Angeles" "Los Angeles" "${sdate}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment