October 5, 2014

How to tell what time it is anywhere on Earth

Bit of a change from the usual python or R that inhabits this blog, and not really impressive either, but it does solve the problem of knowing what time it is on dodgier corners of the planet than this one (eg every one, IMO :) ):

#!/bin/sh
case $1 in 
     -z) env TZ=$2 date
  ;;
     -h) echo "$0 -z [timezone listed in /usr/share/zoneinfo, defaults to localtime]"
  ;;
     *) date
 ;;
esac
And executing this, a few times, to illustrate the paths of execution:

% sh ./bin/worldtime.sh -z HongKong
Sun  5 Oct 2014 15:09:46 HKT
% sh ./bin/worldtime.sh
Sun  5 Oct 2014 00:10:48 PDT
% sh ./bin/worldtime.sh -h
./bin/worldtime.sh -z [timezone listed in /usr/share/zoneinfo, defaults to localtime]

No comments:

Post a Comment