Timezone conversion by command line
Solution 1
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
Solution 2
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>'
.
Solution 3
This example is from http://www.pixelbeat.org/cmdline.html#dates
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.
Solution 4
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
Solution 5
Use Wolfram Alpha. To the basic URL…
http://www.wolframalpha.com/input/?i=
append the conversion, with spaces replaced by +
. For example:
http://www.wolframalpha.com/input/?i=5+PM+CET+to+PST
Note that Wolfram Alpha does not seem to recognize BST
as a time zone.
Related videos on Youtube
hendry
Updated on September 17, 2022Comments
-
hendry almost 2 years
I know about http://www.timeanddate.com/worldclock/converter.html
I can't figure out how to query http://www.google.com in a sane natural format like "5pm BST in PST".
Or do I have to write such an app?
-
Dal Hundal almost 14 yearsWhat do you mean exactly? Command line linux? Command you can type into Google? What?!
-
hendry almost 14 yearscommand line in shell and google's query box are both a command line to me
-
hendry almost 14 yearsperhaps a better tool would do cities by airport codes, 5pm LHR in SFO
-
hroptatyr about 7 years@hendry dateutils can do timezone conversion based on iata and icao airport codes:
dateconv 2017-05-16T17:00 --from-zone iata:SFO --zone iata:LHR
->2017-05-17T01:00:00
-
-
hendry almost 14 yearsDidn't know about
tzselect
, thanks. If you enter wrong 'TZ' input you can get misleading results, e.g. TZ=London date Fri Jul 16 10:28:52 London 2010 -
hendry almost 14 yearshow does one quickly look up time zone codes?
-
DavidGamba about 10 years@hendry This is a cool interactive online map: timeanddate.com/time/map/#!cities=241
-
Ben over 7 yearsStrange, but the first way doesn't work for me:
TZ=Europe/Moscow date --date='TZ="Asia/Taipei" 18:00'
Mon Mar 27 18:00:00 CST 2017
-- i.e. it just tells me the date in Taipei, not my local date for that time point. Although manpage says your method is correct. Am I missing something?..coreutils 8.26
, Arch Linux -
exebook about 5 yearsTo find a timezone identifier use somethin like:
timedatectl list-timezones|grep -i taipei
(printsAsia/Taipei
),timedatectl list-timezones|grep -i berlin
(printsEurope/Berlin
),timedatectl list-timezones|grep -i angeles
(printsAmerica/Los_Angeles
) -
cesarpachon about 5 yearsfantastic script! already added to my toolset, thanks! do you think it is possible to render time in columns instead of rows?
-
Iuri Gavronski almost 5 yearsMaybe. I don't see a use for that, though.
-
Ding-Yi Chen almost 3 years@MarSoft Check whether you have /usr/share/zoneinfo/Europe/Moscow
-
Ben almost 3 years@Ding-YiChen yes, I do.
-
jcdl almost 3 yearsFor some reason this doesn't work with the version of
date
that ships with macOS. I've encountered similar issues before and use GNU coreutils. If you use Homebrew, dobrew install coreutils
, then usegdate
(orgdd
, etc.) then this answer works. -
Alex Reds over 2 years@IuriGavronski interesting script. While playing around with it I noticed for the loop for hours goes beyond 24 hours range. It shows minus hours below 00 and goes beyond 24. e.g. Australia/Sydney
Sydney 19 20 21 22 23 24 25 26 27 28 29 30 31 (+11)
. -
Alex Reds over 2 yearsI assume the loop needs to be limited from 00 to 23. Then in the above example, it would be
Sydney 19 20 21 22 23 00 01 02 03 04 05 06 07 (+11)
-
Iuri Gavronski over 2 yearsI never thought about that. I generally don't schedule meetings for those ungodly hours... 😉
-
Iuri Gavronski over 2 yearsGood observation. I don't mind, because the output is just for my own use, but that's a good suggestion.
-
Admin almost 2 yearsAs it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.