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?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityI 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?
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
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
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
)
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>'
.
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.
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.
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
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
Sydney 19 20 21 22 23 24 25 26 27 28 29 30 31 (+11)
.
Dec 8, 2021 at 11:06
Sydney 19 20 21 22 23 00 01 02 03 04 05 06 07 (+11)
Dec 8, 2021 at 11:09
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.
(You are always sure about "source" and "destination" time zones.)
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
Find the locale you want to use
locale -a
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'`
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
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"
.
dateconv 2017-05-16T17:00 --from-zone iata:SFO --zone iata:LHR
->2017-05-17T01:00:00