Created
April 24, 2013 21:05
-
-
Save jamesstout/5455571 to your computer and use it in GitHub Desktop.
Get the current time in all the timezones known to your machine
This file contains 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/bash | |
# Error logging | |
e_error() { | |
printf "$(tput setaf 1)x %s$(tput sgr0)\n" "$@" | |
} | |
# only do this if you know how to set it back | |
# set date/time to 10:00 AM PDT | |
# export TZ=PST8PDT | |
# sudo date 042510002013.00 | |
# OpenSolaris | |
# /usr/share/lib/zoneinfo | |
# OS X and Linux | |
# /usr/share/zoneinfo | |
# default | |
TZ_DIR="/usr/share/zoneinfo" | |
if [ -n "$OSTYPE" ]; then | |
if [[ "$OSTYPE" =~ ^darwin ]] || [[ "$OSTYPE" =~ ^linux ]]; then | |
TZ_DIR="/usr/share/zoneinfo" | |
elif [[ "$OSTYPE" =~ ^solaris ]]; then | |
TZ_DIR="/usr/share/lib/zoneinfo" | |
fi | |
fi | |
if [ ! -d "$TZ_DIR" ]; then | |
e_error "$TZ_DIR does not exist" | |
exit 1 | |
fi | |
cd "$TZ_DIR" | |
# get all the timezones, trim off first 2 chars: "./" | |
# store in array for repeat use | |
declare -a all_tz=(`find . | cut -c 3-`) | |
# get max len for output formatting | |
m=-1 | |
for x in ${all_tz[@]} | |
do | |
if [ ${#x} -gt $m ] | |
then | |
m=${#x} | |
fi | |
done | |
for index in ${!all_tz[*]} | |
do | |
export TZ=${all_tz[$index]} | |
xx=`date '+%d %b %I:%M %p'` | |
printf "%-*s %s\n" $m "$TZ" "$xx" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment