35

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?

4
  • 1
    What do you mean exactly? Command line linux? Command you can type into Google? What?!
    – Dal Hundal
    Jul 16, 2010 at 9:37
  • command line in shell and google's query box are both a command line to me
    – hendry
    Jul 16, 2010 at 9:42
  • 1
    perhaps a better tool would do cities by airport codes, 5pm LHR in SFO
    – hendry
    Jul 16, 2010 at 9:42
  • @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
    – hroptatyr
    May 16, 2017 at 9:10

8 Answers 8

60

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
5
  • 1
    Strange, 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
    – MarSoft
    Mar 27, 2017 at 1:45
  • 5
    To find a timezone identifier use somethin like: timedatectl list-timezones|grep -i taipei (prints Asia/Taipei), timedatectl list-timezones|grep -i berlin (prints Europe/Berlin), timedatectl list-timezones|grep -i angeles (prints America/Los_Angeles)
    – exebook
    May 24, 2019 at 5:45
  • @MarSoft Check whether you have /usr/share/zoneinfo/Europe/Moscow Aug 20, 2021 at 2:20
  • @Ding-YiChen yes, I do.
    – MarSoft
    Aug 20, 2021 at 11:09
  • If you don't have timedatectl installed, this may work to find your timezone ID: find /usr/share/zoneinfo/ | grep -i amsterdam
    – AstroFloyd
    Feb 1 at 17:19
11

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
  • 2
    For 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, do brew install coreutils, then use gdate (or gdd, etc.) then this answer works.
    – jcdl
    Sep 14, 2021 at 14:35
8

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.

1
  • 3
    Didn'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
    Jul 16, 2010 at 10:29
5

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

8
  • fantastic script! already added to my toolset, thanks! do you think it is possible to render time in columns instead of rows? May 24, 2019 at 12:29
  • Maybe. I don't see a use for that, though. Jul 26, 2019 at 21:22
  • @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
    Dec 8, 2021 at 11:06
  • I 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)
    – Alex Reds
    Dec 8, 2021 at 11:09
  • I never thought about that. I generally don't schedule meetings for those ungodly hours... 😉 Dec 9, 2021 at 12:54
2

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.

2
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
    

    or nicely processed by country at https://metacpan.org/pod/DateTime::TimeZone::Catalog#Zones-by-Country

  2. Find the locale you want to use

    locale -a
    
  3. Convert in one line:

    From Central European Time (in Prague) to a few popular time zones:

    srct='today 09:30' srctz='Europe/Prague' LC_TIME="POSIX" ; for z in America/Chicago UTC/UTC Europe/London Europe/Prague Asia/Kolkata ; do t=`TZ=$z date --date "TZ=\"$srctz\" $srct" +'%a %b %d %Y %R %Z (UTC offset=%:z) '` ; printf "In %-15s: %s\n" "$z" "$t" ; done ; printf "Which is %d seconds since Thu Jan 01 1970 00:00:00 UTC\n" `date --date "TZ=\"$srctz\" $srct" +'%s'`
    
0

I found Iuri's script very useful. I wanted to port it to GNU date cause his version uses some BSD options and it couldn't run it.

#!/bin/bash
# ig20180122 - displays meeting options in other time zones
# ml20220712 - Linux GNU date compatible
# 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='Europe/Madrid'
# set the most common places
place[1]='America/Toronto'
place[2]='America/Chicago' # Houston as well
place[3]='Europe/Amsterdam'
place[4]='Europe/Dublin'
place[5]='Europe/Kiev'
place[6]='Asia/Hong_Kong'
# add cities using place[5], etc.
# set the date format for search
dfmt="%m/%d" # date format for meeting date \
# New format so It can be used as argument
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"
date -d $mdate "$hfmt" # GNU linux compliant
here=`TZ=$myplace date -d $mdate +%z` # Same Here
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 -d "$mdate" +%z` # same here
    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

Output data for today:

meet.sh

Check other days:

meet.sh 09/22
1
  • As 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.
    – Community Bot
    Jul 12, 2022 at 11:30
0

I had a problem that many others probably share - my server (which works in UTC) queries a REST API in a remote server that is set to San Francisco time, and it returns date/time fields with no timezone specified, e.g. "2023-05-23T12:50:37". I need to know what that date/time is in UTC (or in unixtime), for comparison with other date/time fields. To do that, my bash script needs to know if San Francisco is currently in Winter time (PST) or Summer time (PDT).

[ Obviously the REST API should return date/time values including the TZ or offset, or stick to UTC, but I don't own it. ]

So I run something like this:

SERVER_TZ_NAME="US/Pacific"

# Work out which time-zone (short name) is used at the specified date/time
# - for US/Pacific, this will return either PST or PDT, depending on the
# time of year
SERVER_TZ=$(TZ="$SERVER_TZ_NAME" date -d "$returned_timestring" +%Z'

# Convert to unixtime (could convert to UTC, or local time-zone, or whatever)
returned_timestamp=$(date -d "$returned_timestring $SERVER_TZ" +%s)

where $returned_timestring is the timestamp in the remote server's time-zone, but with no TZ information included, e.g. "2023-05-23T12:50:37".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .