Linux UTC Offset – How to Get from Current or Other Timezones

datedaylight-savinglinuxtimezoneutc

In Chile the case is very particular as the days of daylight saving changes are different a year from another…

Is there a function to get for given day at given UTC time the UTC offset?

I saw on a Suse documentation that something like zdump -v /usr/share/zoneinfo/Chile/Continental makes me enable to get all changings through years, but the job has to be done still… any command to do that?

Or/and is there a function with a given date and time from given timezone to UTC?
And its reverse?

How does linux handle these changes? didn't find more documentation than Suse one.

Best Answer

You can use the date command. You set the timezone and then specify the date and time. The command will return that time with the -03 or -04, so you will know if DST was in effect.

For example, for Chile/Continental:

Before DST change this year:

$ TZ=Chile/Continental date --date='2020-04-03 11:00 +00'
Fri Apr  3 11:00:00 -03 2020

After DST change this year:

$ TZ=Chile/Continental date --date='2020-04-06 11:00 +00'
Mon Apr  6 11:00:00 -04 2020

To undo that, just set TZ to UTC and change the offset:

$ TZ=UTC date --date='2020-04-03 11:00 -04'
Related Topic