2

I need to convert time from localtimezone (CET/CEST) to Sydney timezone (AEDT/AEST). I tried something like this:

export date=$(date "+%Y-%m-%d %H:%M:%S AEDT")
date "+%Y-%m-%d %H:%M:%S %Z" -d "$date"

It doesn't work, it doesn't recognize "AEDT", however I tried this with "UTC" and it worked. I tried to replace "AEDT" with "Australia/Sydney" (I found it in /usr/share/zoneinfos), but result was the same.

I would appreciate any advices, I am using korn shell. Thanks.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Wlad
  • 123
  • 1
  • 4
  • 1
    Possible duplicate of [How can I have `date` output the time from a different timezone?](http://unix.stackexchange.com/questions/48101/how-can-i-have-date-output-the-time-from-a-different-timezone) – Omnipresence Oct 31 '14 at 13:54

2 Answers2

1

If you want to convert a random time from the local timezone to a time in another timezone:

$ date -d @$(date +%s -d '2014/10/01 12:34:56')
Wed Oct  1 12:34:56 CEST 2014
$ TZ=Australia/Sydney date -d @$(date +%s -d '2014/10/01 12:34:56')
Wed Oct  1 20:34:56 EST 2014

I use seconds since the unix epoch as the natural way to communicate a point in time.

wurtel
  • 15,835
  • 1
  • 29
  • 35
0

Using a couple of scripting languages:

perl -MDateTime -E 'say DateTime->now(time_zone => "local")->set_time_zone("Australia/Sydney")->strftime("%F %T %Z")'

echo 'puts [clock format [clock seconds] -format {%Y-%m-%d %T %Z} -timezone ":Australia/Sydney"]' | tclsh
glenn jackman
  • 84,176
  • 15
  • 116
  • 168