Timezone conversion by command line

I know about

I can't figure out how to query in a sane natural format like "5pm BST in PST".

Or do I have to write such an app?

4

6 Answers

It's 6pm in Taipei, what time is it here?

date --date='TZ="Asia/Taipei" 18:00'
Fri Jul 16 11:00:00 BST 2010

At 11am here in London, what time is it in Taipei?

TZ=Asia/Taipei date -d "11:00 BST"
Fri Jul 16 18:00:00 CST 2010
4

I think this is closer to what the OP asked (Since he doesn't necessarily know that BST is Taipei? and the answer doesn't explain how to get to "Asia/Taipei" from 'BST').

First my current date:

$ date
Mon Apr 21 13:07:21 MDT 2014

Then the date I want to know:

$ date -d '5pm BST'
Mon Apr 21 15:00:00 MDT 2014

So I know that 5pm BST is 2 hours away.

I usually forget if I have to add or remove two hours from EDT times so I have a little script with the common timezones I have to work with:

$ cat tz
#!/bin/bash
TZ='America/Edmonton' date
TZ='America/Chicago' date
TZ='America/New_York' date

And the output:

$ tz
Mon Apr 21 13:12:32 MDT 2014
Mon Apr 21 14:12:32 CDT 2014
Mon Apr 21 15:12:32 EDT 2014

Valid locations for your tz script can be found here /usr/share/zoneinfo.

But again, for times in the future I just use date -d '<time> <timezone>'.

1

This example is from

It gives the local time corresponding to 9AM on the west coast of the US, accounting for differing day light savings transitions.

date --date='TZ="America/Los_Angeles" 09:00 next Fri'

Use tzselect to get the TZ. The PST format is ambiguous. IST = Indian Standard Time and Irish Summer Time for example.

1

I know it is an old thread, but I needed a code for the same use case and, based on the ideas here, developed this little bash script:

#!/bin/bash
# ig20180122 - displays meeting options in other time zones
# set the following variable to the start and end of your working day
myday="8 20" # start and end time, with one space
# set the local TZ
myplace='America/Sao_Paulo'
# set the most common places
place[1]='America/Toronto'
place[2]='America/Chicago' # Houston as well
place[3]='Europe/Amsterdam'
place[4]='Europe/Dublin'
# add cities using place[5], etc.
# set the date format for search
dfmt="%m-%d" # date format for meeting date
hfmt="+%B %e, %Y" # date format for the header
# no need to change onwards
format1="%-10s " # Increase if your cities are large
format2="%02d "
mdate=$1
if [[ "$1" == "" ]]; then mdate=`date "+$dfmt"`; fi
date -j -f "$dfmt" "$hfmt" "$mdate"
here=`TZ=$myplace date -j -f "$dfmt" +%z "$mdate"`
here=$((`printf "%g" $here` / 100))
printf "$format1" "Here"
printf "$format2" `seq $myday`
printf "\n"
for i in `seq 1 "${#place[*]}"`
do there=`TZ=${place[$i]} date -j -f "$dfmt" +%z "$mdate"` there=$((`printf "%g" $there` / 100)) city[$i]=${place[$i]/*\//} tdiff[$i]=$(($there - $here)) printf "$format1" ${city[$i]} for j in `seq $myday` do printf "$format2" $(($j+${tdiff[$i]})) done printf "(%+d)\n" ${tdiff[$i]}
done

You can either use to check the time differences today or in a future date:

16:08 $ meet
January 22, 2019
Here 08 09 10 11 12 13 14 15 16 17 18 19 20
Toronto 05 06 07 08 09 10 11 12 13 14 15 16 17 (-3)
Chicago 04 05 06 07 08 09 10 11 12 13 14 15 16 (-4)
Amsterdam 11 12 13 14 15 16 17 18 19 20 21 22 23 (+3)
Dublin 10 11 12 13 14 15 16 17 18 19 20 21 22 (+2)
16:13 $ meet 05-24
May 24, 2019
Here 08 09 10 11 12 13 14 15 16 17 18 19 20
Toronto 07 08 09 10 11 12 13 14 15 16 17 18 19 (-1)
Chicago 06 07 08 09 10 11 12 13 14 15 16 17 18 (-2)
Amsterdam 13 14 15 16 17 18 19 20 21 22 23 24 25 (+5)
Dublin 12 13 14 15 16 17 18 19 20 21 22 23 24 (+4)
16:13 $ 

HTH

6

Use Wolfram Alpha. To the basic URL…

append the conversion, with spaces replaced by +. For example:

Note that Wolfram Alpha does not seem to recognize BST as a time zone.

2

Unambiguous one-liner

(You are always sure about "source" and "destination" time zones.)

  1. Find the source and destination cities

    less /usr/share/zoneinfo/zone.tab
  2. Convert in one line:

    From Central European Time (in Prague) to India Standard Time (in Kolkata):

    TZ=Asia/Kolkata date --date 'TZ="Europe/Prague" 2022-02-15 09:45' +'%F %R %Z (UTC offset=%:z) # Unix timestamp=%s'
    2022-02-15 14:15 IST (UTC offset=+05:30) # Unix timestamp=1644914700

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like