unixtimezonetimezone-offsetiana

How to get the offset for a specific date + time + iana time zone (unix)


I am using the command below to return the offset and this works well for my current time zone.

date -d "2020-10-05 17:33:57" +"%:z"

I am currently in Australia/Brisbane time zone. The offset returned is +10:00.

I would to get the offset for Australia/Sydney (which is +11:00 at the moment due to daylight savings).

How can I add the IANA time zone to my command so that the correct offset is returned?

Any help would be appreciated.


Solution

  • just set the time zone upfront,

    TZ=Australia/Sydney date -d "2020-10-05 17:33:57" +"%:z"
    # +11:00
    

    See How can I have date output the time from a different timezone? for more details.