Questions tagged [dst]

DST is the tag for Daylight Saving Time issues. DST, also known as summer time, starts when a time zone shifts its clocks forward (in the spring), and ends when the clocks shift back (in the fall).

DST is the tag for Daylight Saving Time issues. Daylight Saving Time is the period when a time zone shifts its time forward in the spring (usually by one hour) and then shifts back in the fall. This creates many programming issues dealing with the lost hour in the spring, and the extra hour in the fall.

Daylight saving time is sometimes called "Summer Time", as time is changed during the summer as compared to the rest of the year. Keep in mind that the northern and southern hemispheres observe summer at different times.

Also, sometimes the term is erroneously called "daylight savings time", or just "daylight savings". Neither term is correct. There is no "s".

To illustrate the effects of DST, consider the following graphs. These represent the daylight saving time transitions for the US Pacific time zone.

                Spring Forward DST Transition

                Fall Back DST Transition

While other time zones may transition at different points in time, the behaviors are similar. There is a "gap" of missing local time during the "spring forward" transition, and there is an "overlap" of ambiguous local time during the "fall back" transition.

These graphs also demonstrate the mathematical behaviors of the transitions:

  • Conversion from UTC to Local Time is a function over the range of all time that the local time zone was in existence.

    • However, it may not be a continuous function, due to the transitional adjustments that are made for daylight saving time.

    • Keep in mind that the local time zone was probably not always well defined, or it may have been defined using some earlier calendar system.

  • Conversion from Local Time to UTC is not a pure function because:

    • There may be a discontinuity for the "spring forward" transition, so a local time in this range would be undefined.

    • There may be a range where it is not a function at all, because there is more than one possible outcome for a single input, which occures during the "fall-back" transition.

    • This can lead to problems because some people think that you can always convert in either direction, which is false for any time zone that observes daylight saving time.

Also keep in mind that in the Northern Hemisphere, the "spring forward" transition occurs early in the year and the "fall back" transition occurs late in the year. However, in the Southern Hemisphere the seasons are inverted, so the "fall back" transition typically comes early in the year, while the "spring forward" transition comes late in the year.

Also keep in mind:

  • Not every time zone of the world uses daylight saving time. In fact, the majority do not. See this Wikipedia Article for details.

  • Of those that uses it, each time zone decides how DST applies. Different countries will start and end daylight time at different dates.

  • Not every time zone transitions by one hour. For example, the Australia/Lord_Howe time zone only shifts by 30 minutes.

  • Governments of the world often make changes to how they want to follow DST. You cannot assume that the current rules have always applied in the past or always will apply in the future.

  • DST transition days will have less or more actual time than 24 hours. In most cases, spring-forward days will have 23 hours, and fall-back days will have 25.

  • There are not always exactly a single pair of DST transitions in a given year. Other real-world cases include:

    • One spring transition : This occurs when a time zone decides to stay on "permanent summer time". For example, in 2015 the Turks and Caicos Islands sprung forward in March and stayed there. This is often modeled as a change in base-offset from UTC-5 to UTC-4.

    • One fall transition : This occurs when a time zone that was on "permanent summer time" switches back to standard time. This occurred across Russia in 2014.

    • Two transitions : This is the common case.

    • Three transitions : This is much rarer, but occurred in 2011 in Samoa. The first two transitions were for DST, and the third occurred when 24 hours were skipped to change the island's base-offset from UTC-10 to UTC+14.

    • Four transitions : This occurs when a country that observes DST decides to suspend it temporarily. This has been done in both Egypt and Morocco for the observation of Ramadan.

1185 questions
2101
votes
30 answers

Daylight saving time and time zone best practices

I am hoping to make this question and the answers to it the definitive guide to dealing with daylight saving time, in particular for dealing with the actual change overs. If you have anything to add, please do Many systems are dependent on keeping…
Oded
  • 463,167
  • 92
  • 837
  • 979
171
votes
15 answers

How to check if DST (Daylight Saving Time) is in effect, and if so, the offset?

This is a bit of my JS code for which this is needed: var secDiff = Math.abs(Math.round((utc_date-this.premiere_date)/1000)); this.years = this.calculateUnit(secDiff,(86400*365)); this.days =…
Jo Smo
  • 5,847
  • 9
  • 39
  • 64
92
votes
7 answers

MySQL datetime fields and daylight savings time -- how do I reference the "extra" hour?

I'm using the America/New York timezone. In the Fall we "fall back" an hour -- effectively "gaining" one hour at 2am. At the transition point the following happens: it's 01:59:00 -04:00 then 1 minute later it becomes: 01:00:00 -05:00 So if you…
Aaron
  • 2,459
  • 1
  • 20
  • 23
84
votes
2 answers

Does UTC observe daylight saving time?

I am trying to write a script where i want to convert any timezone to UTC and reverse. But from some where i came to know that while converting any timezone to UTC with or without DST consideration it will give the same UTC time. For example: If i…
0001
  • 853
  • 1
  • 6
  • 7
74
votes
6 answers

Is it always a good idea to store time in UTC or is this the case where storing in local time is better?

Generally, it is the best practice to store time in UTC and as mentioned in here and here. Suppose there is a re-occurring event let's say end time which is always at the same local time let's say 17:00 regardless of whether there is Daylight saving…
Sun
  • 1,851
  • 2
  • 20
  • 26
66
votes
5 answers

Determine Whether Daylight Savings Time (DST) is Active in Java for a Specified Date

I have a Java class that takes in the latitude/longitude of a location and returns the GMT offset when daylight savings time is on and off. I am looking for an easy way to determine in Java if the current date is in daylight savings time so I can…
gelgamil
  • 841
  • 1
  • 7
  • 6
58
votes
2 answers

Best practices with saving datetime & timezone info in database when data is dependant on datetime

There were quite a few questions about saving datetime & timezones info in DB but more on the overall level. Here I'd like to address a specific case. System specs We have an Orders system database It is a multi-tenant system where tenants can use…
daneejela
  • 8,695
  • 6
  • 29
  • 40
51
votes
6 answers

Python daylight savings time

How do I check if daylight saving time is in effect?
Pawel Furmaniak
  • 4,044
  • 3
  • 26
  • 33
44
votes
2 answers

Daylight Savings and Cron

If Cron has a job scheduled to run at 2 am and one at 3 am how would those jobs be affected by daylight savings time? When the time shifts back an hour does the time go from 2:59:59 am to 2:00:00 am directly? Meaning that the 2 am job would run…
Joe W
  • 1,576
  • 2
  • 26
  • 33
43
votes
1 answer

How to store repeating dates keeping in mind Daylight Savings Time

I'm storing events in my database. I have 'start' and 'end' date times, 'tickets_start' and 'tickets_end' (for when ticket sales actually start/end - as opposed to the start/end of the actual event). So far, I've built methods that do all the fun…
Dave
  • 27,341
  • 18
  • 106
  • 177
39
votes
4 answers

.NET DateTime.Now returns incorrect time when time zone is changed

This problem occurred during daylight saving time change. After the change occurred, we've noticed that our server application started writing into the log incorrect time - one hour ahead which means that .NET caches time zone offset. We had to…
GregK
  • 1,593
  • 2
  • 14
  • 19
36
votes
8 answers

Check if daylight savings is in effect?

How to check if in Denmark daylight time savings has taken effect, if so, then add 1 hour to my data, else not? I have a xml file:
Megaoctane
  • 779
  • 3
  • 8
  • 10
34
votes
5 answers

Convert UTC DateTime to another Time Zone

I have a UTC DateTime value coming from a database record. I also have a user-specified time zone (an instance of TimeZoneInfo). How do I convert that UTC DateTime to the user's local time zone? Also, how do I determine if the user-specified time…
Mark Richman
  • 26,790
  • 23
  • 85
  • 150
33
votes
3 answers

PHP daylight saving time detection

I need to send an email to users based wherever in the world at 9:00 am local time. The server is in the UK. What I can do is set up a time difference between each user and the server's time, which would then perfectly work if DST didn't…
Nicolas
  • 2,510
  • 6
  • 24
  • 38
33
votes
5 answers

Timezone conversion in a Google spreadsheet

I know this looks simple. In a Google spreadsheet, I have a column where I enter time in one timezone (GMT) And another column should automatically get time in another time zone(Pacific Time) GMT | PT ----------|------------ 5:00 AM | 9:00…
skay
  • 593
  • 2
  • 5
  • 15
1
2 3
78 79