Created
July 16, 2025 23:48
-
-
Save yeiichi/04fb494827dfc5cdbf547431ce42e67a to your computer and use it in GitHub Desktop.
Return ISO 8601 datetime.now() in the given time zone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Return ISO 8601 datetime.now() in the given time zone | |
# Ask user for timezone abbreviation | |
read "abbr?Enter timezone (e.g. jst, utc, est, pst): " | |
abbr="${abbr:l}" # normalize to lowercase | |
# Map common abbreviations to IANA timezone names | |
case "$abbr" in | |
jst) tz="Asia/Tokyo" ;; | |
utc) tz="UTC" ;; | |
est) tz="America/New_York" ;; | |
pst) tz="America/Los_Angeles" ;; | |
cet) tz="Europe/Paris" ;; | |
*) echo "Unsupported timezone: $abbr"; exit 1 ;; | |
esac | |
# Print ISO 8601 datetime | |
python3 -c " | |
from datetime import datetime | |
import zoneinfo | |
dt = datetime.now(zoneinfo.ZoneInfo('$tz')) | |
print(dt.strftime('%Y-%m-%dT%H:%M:%S%z')[:-2] + ':' + dt.strftime('%z')[-2:]) | |
" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment