How to get the hour difference between two time zones in bash

Olivier Olivier.Nicole at cs.ait.ac.th
Tue Mar 29 02:38:07 UTC 2022


Hi,

Bo Berglund <bo.berglund at gmail.com> writes:

> I have a scriot that runs every day and it operates on data from both my
> location and New York. It sets up at jobs at certain times in New York but doing
> it from Stockholm.

I have been doing the same thing in Perl by modifying the timezone. It
is working just fine. It is easy to manually change the date on your
machiner to test various date configurations and confirm it is working.

BUT: it relies on the fact that your OS has uptodate list of DST for
each time zone. And these dates and times are known to be prone to be
varying and your OS maybe lagging in keeping the current/latest data.

If it is absolutely critical that the job starts at the right NY time,
it may be better that NY provide their local time to you, so if you are
off, it means they did not provided the correct time.

There could be a web page sending the date and time.

Best regards,

Olivier



> I would like to automatically handle the time difference between the two sites
> in the script.
> The normal difference is 6 hours but for a couple of weeks in March it is 5
> hours and in the fall it is 7 hours because the US and Sweden switches to/from
> DST at different dates in March and October.
>
> I just ran into the problem and could almost fix it by setting the TZ variable
> in the script, but it only worked during the diff time and then it screwed up
> again.
>
> So I need to calculate on the start of the script which is the current number of
> hours difference between Stockholm and New York.
>
> How can this be done?
>
>
> -- 
> Bo Berglund
> Developer in Sweden

-- 




More information about the ubuntu-users mailing list