Yonatan Faigenbaum
Yonatan Faigenbaum

Reputation: 79

why Linux system time adds and substracts one hour every 6 months?

When calculating the number of seconds between 2 consecutive days there should be 86400 seconds (24*60*60).
But twice a year its not the case...
One time there are 23 hours on the day and 6 months later there are 25 hours in the day.
Why does this happen?

I ran a code to check the number of seconds between 2 days from 2005 till 2019 and all year there are exactly 24 hours except 2 days were there are 23 and 25. Why does this happen? Here is a summery of my results - The difference column is the number of seconds between this day and the previous one to 86400 seconds

+------------+------------+-------------------+
|   dates    | difference | number_of_seconds |
+------------+------------+-------------------+
| 2005-04-02 |       3600 |             82800 |
| 2005-10-10 |      -3600 |             90000 |
| 2006-04-01 |       3600 |             82800 |
| 2006-10-02 |      -3600 |             90000 |
| 2007-03-31 |       3600 |             82800 |
| 2007-09-17 |      -3600 |             90000 |
| 2008-03-29 |       3600 |             82800 |
| 2008-10-06 |      -3600 |             90000 |
| 2009-03-28 |       3600 |             82800 |
| 2009-09-28 |      -3600 |             90000 |
| 2010-03-27 |       3600 |             82800 |
| 2010-09-13 |      -3600 |             90000 |
| 2011-04-02 |       3600 |             82800 |
| 2011-10-03 |      -3600 |             90000 |
| 2012-03-31 |       3600 |             82800 |
| 2012-09-24 |      -3600 |             90000 |
| 2013-03-30 |       3600 |             82800 |
| 2013-10-28 |      -3600 |             90000 |
| 2014-03-29 |       3600 |             82800 |
| 2014-10-27 |      -3600 |             90000 |
| 2015-03-28 |       3600 |             82800 |
| 2015-10-26 |      -3600 |             90000 |
| 2016-03-26 |       3600 |             82800 |
| 2016-10-31 |      -3600 |             90000 |
| 2017-03-25 |       3600 |             82800 |
| 2017-10-30 |      -3600 |             90000 |
| 2018-03-24 |       3600 |             82800 |
| 2018-10-29 |      -3600 |             90000 |
+------------+------------+-------------------+

Here is an example of the code that I ran inside my full code -

echo $((($(date +%s --date 2006-03-31)-$(date +%s --date 2006-03-30))))
echo $((($(date +%s --date 2006-04-01)-$(date +%s --date 2006-03-31))))
echo $((($(date +%s --date 2006-04-02)-$(date +%s --date 2006-04-01))))

Upvotes: 1

Views: 76

Answers (1)

JGNI
JGNI

Reputation: 4013

The date command with the %s format gives you the wall clock time in seconds from the epoch and your location has daylight savings time. So when you change to and from summer time you either gain or loose an hour.

Upvotes: 4

Related Questions