Skip to content

Instantly share code, notes, and snippets.

@mattcanty
Created October 19, 2021 11:29
Show Gist options
  • Save mattcanty/73773f87689a130b32f497aabba15b0e to your computer and use it in GitHub Desktop.
Save mattcanty/73773f87689a130b32f497aabba15b0e to your computer and use it in GitHub Desktop.

Convert given time to multiple timezones. Let people know in other TZs when you intend to perform some action.

Like This

➜  ~ btz 2100
04:00 HKT | 22:00 CEST | 21:00 BST

Take it further

Find more timezones. On MacOS:

ls /usr/share/zoneinfo

Update timezones in btz!

Broadcast Time Zone
#!/bin/sh
# Convert given time to multiple timezones.
# Let people know in other TZs when you intend
# to perform some action.
timezones=('Asia/Hong_Kong' 'Europe/Warsaw' 'Europe/London')
separator=' | '
time_format="%H:%M %Z"
local_date_now=$(date +%s)
local_date_future=$(date -j $1 +%s)
diff=$(expr $((local_date_future-local_date_now)))
[ $diff -lt 0 ] && adjust_prefix="" || adjust_prefix="+"
results=()
for tz in ${timezones[@]}
do
results+=("$(TZ=$tz date -v $adjust_prefix$diff"S" +"$time_format")")
done
output=$(printf "${separator}%s" "${results[@]}")
output=${output:${#separator}}
echo $output
@Kyslik
Copy link

Kyslik commented Jul 1, 2022

A tip: you can slap this inside your *rc file and use it as shell function.

btz() {
// body of above Gist
}

@mattcanty
Copy link
Author

@Kyslik ❤️

@harshagv
Copy link

Super useful ♥️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment