Skip to content

Instantly share code, notes, and snippets.

@yeiichi
Created July 16, 2025 23:48
Show Gist options
  • Save yeiichi/04fb494827dfc5cdbf547431ce42e67a to your computer and use it in GitHub Desktop.
Save yeiichi/04fb494827dfc5cdbf547431ce42e67a to your computer and use it in GitHub Desktop.
Return ISO 8601 datetime.now() in the given time zone
#!/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