I have a date/time string which is extracted from a filename. I know that the timestamp was written using time zone A and I need to convert it to time zone B for further processing. Is this possible in bash?


filenameTimestamp="2015-01-20 18:05:02"

I assume I will have to parse the string using time zone A and then output it again to a string using time zone B.

  • 1
    Aren't Sydney and Brisbane in the same TZ? UTC +10. May 29, 2015 at 4:49
  • no, sydney has daylight savings time and is 1 hour different in summer
    – pstanton
    May 29, 2015 at 5:33
  • i should have used a summer timestamp in the example sorry!
    – pstanton
    May 29, 2015 at 5:34

1 Answer 1


To interpret the date in Sydney to a date in Los Angeles, USA:

$ sec=$(TZ="Australia/Sydney" date +'%s' -d "2015-05-20 18:05:02")
$ TZ="America/Los_Angeles" date -d "@$sec"
Wed May 20 01:05:02 PDT 2015

Here is the result for Brisbane:

$ TZ="Australia/Brisbane" date -d "@$sec"
Wed May 20 18:05:02 AEST 2015

How it works

  • TZ="Australia/Sydney" date +'%s' -d "2015-05-20 18:05:02"

    This temporarily sets the timezone to Sydney and converts the date "2015-05-20 18:05:02" to time in seconds since epoch (UTC).

  • sec=$(TZ="Australia/Sydney" date +'%s' -d "2015-05-20 18:05:02")

    This saves the time in seconds since epoch (UTC) into the shell variable sec.

  • TZ="America/Los_Angeles" date -d "@$sec"

    This temporarily sets the timezone to Los Angeles and interprets the the date given by sec.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.