# ESP8266 Daylight Savings Time (DST) not working

**URL:** <https://forum.arduino.cc/t/esp8266-daylight-savings-time-dst-not-working/514213>\
**Category:** 3rd Party Boards\
**Created:** [March 15, 2018, 1:09am UTC](https://forum.arduino.cc/t/esp8266-daylight-savings-time-dst-not-working/514213 "2018-03-15T01:09:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![frank2644](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/frank2644/32/1126542_2.png) [@frank2644](https://forum.arduino.cc/u/frank2644)\
**Post date:** [March 15, 2018, 1:09am UTC](https://forum.arduino.cc/t/esp8266-daylight-savings-time-dst-not-working/514213/1 "2018-03-15T01:09:39Z")

</div>

I am using the time.h library to get NTP time and that works well. However, it doesn't seem to adjust for DST.

Related statements:

#include \<time.h\>  
configTime(-5 \* 3600, 1\*3600, "[pool.ntp.org](http://pool.ntp.org)", "[time.nist.gov](http://time.nist.gov)");  
time\_t now = time(nullptr);  
Serial.println(ntptime);

I have googled the problem and tried a lot of suggestions, but no luck. Some of the Google searches seem to say that DST doesn't work. Although the discussion was over my head so I might not have understood it correctly.

I would appreciate any help to get this working.

Alternatively is there is a simple way to determine when DST is active so I can adjust the time myself?

Thanks,  
Frank

---

<div class="post-metadata">

**Author:** ![Perehama](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perehama/32/256713_2.png) [@Perehama](https://forum.arduino.cc/u/Perehama)\
**Post date:** [March 22, 2018, 3:15pm UTC](https://forum.arduino.cc/t/esp8266-daylight-savings-time-dst-not-working/514213/2 "2018-03-22T15:15:16Z")

</div>

NTP time is UTC as is now() from time.h and UTC doesn't account for daylight savings.

You need to offset UTC to local time for both standard time and daylight time.

Consider using [Jack Christensen's Arduino Timezone Library](https://github.com/JChristensen/Timezone) to set up your offsets and daylight savings rules.

---

<div class="post-metadata">

**Author:** ![frank2644](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/frank2644/32/1126542_2.png) [@frank2644](https://forum.arduino.cc/u/frank2644)\
**Post date:** [March 22, 2018, 4:43pm UTC](https://forum.arduino.cc/t/esp8266-daylight-savings-time-dst-not-working/514213/3 "2018-03-22T16:43:29Z")

</div>

> Perehama:  
> NTP time is UTC as is now() from time.h and UTC doesn't account for daylight savings.
> 
> You need to offset UTC to local time for both standard time and daylight time.
> 
> Consider using [Jack Christensen's Arduino Timezone Library](https://github.com/JChristensen/Timezone) to set up your offsets and daylight savings rules.

Thanks, I looked at the Timezone library but I found some home grown code on the net that I was able to use.

---

<div class="post-metadata">

**Author:** ![bperrybap](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bperrybap/32/605367_2.png) [@bperrybap](https://forum.arduino.cc/u/bperrybap)\
**Post date:** [November 4, 2018, 12:47am UTC](https://forum.arduino.cc/t/esp8266-daylight-savings-time-dst-not-working/514213/4 "2018-11-04T00:47:36Z")

</div>

I know this is an old thread, but for those that are still struggling with this, I posted an example to a git hub issue.  
The example shows how to use NTP with timezone and DST support by avoiding the broken timezone offset support and using the built in TZ string support.

> <https://github.com/esp8266/Arduino/issues/4637#issuecomment-435611842>
>
> \#### Platform
> 
> \- Hardware: \[ESP-12\]
> \- Core Version: \[2.4.1\]
> \- Developmen…t Env: \[Arduino IDE\]
> \- Operating System: \[Linux Mint 17.3\]
> 
> \### Settings in IDE
> 
> \- Module: \[Wemos D1\]
> \- Flash Mode: \[qio|dio|other\]
> \- Flash Size: \[4MB/1MB\]
> \- lwip Variant: \[v1.4|v2 Lower Memory|Higher Bandwidth\]
> \- Reset Method: \[ck|nodemcu\]
> \- Flash Frequency:	\[40Mhz\]
> \- CPU Frequency: \[80Mhz|160MHz\]
> \- Upload Using: \[OTA|SERIAL\]
> \- Upload Speed: \[115200|other\] (serial upload only)
> 
> 
> \### Problem Description
> The are some serious issues with how timezone offsets are being handled in various time functions.
> There was mention of some issues in the discussion about the 
> NTP-TZ-DST.ino demo sketch in issue #3835
> That issue mentioned issues with gmtime() and localtime() but the issues are much more serious.
> Here is the behavior I've seen - using the NTP-TZ-DST.ino demo sketch with a few tweaks to see the behavior of gettimeofday() as well.
> The results were the same regardless of whether NTP was used or the "fake" RTC mode was used.
> 
> \* The time\_t returned by time() does not equal the tv\_sec value returned by gettimeofday()
> They should always be the same value.
> 
> \* gettimeofday() in the tv\_sec member returned, is always supposed to return the number of seconds since the epoch without any consideration or alteration based on local timezone.
> This is working correctly.
> 
> \* time() is always supposed to return the number of seconds since the epoch without any consideration or alteration based on local timezone.
> This is not working correctly
> time() is returning a time\_t that has been adjusted/modified and is offset by the specified timezone information.
> This is incorrect. time() has modified that actual time\_t timestamp it returns. time\_t timestamp values are not be modified for the local time. Any correction for local time should be handled by localtime() or ctime()
> 
> \* gmtime() and localtime() are currently generating the same broken down time elements.
> This is incorrect.
> They both take the time\_t value and break down it into its components based on the time\_t value provided with no adjustments for timezone.
> The issue is actually with localtime()
> localtime() is behaving just like gmtime() and is not adjusting the time for the timezone offsets.
> This is easily be demonstrated by handing both localtime() and gmtime() a zero value time\_t.
> Both will generate the identical GMT time at the epoch.
> 
> These issues have likely been masked/hidden since many users that are setting timezone information are then calling localtime() with the time\_t value from time(). While the fields created by localtime() when handed a time\_t from time() will be correct, the time adjustment is being done incorrectly since the time\_t was adjusted by time() rather than localtime() doing the timezone adjustment.
> 
> localtime() will fail to work correctly when handed the tv\_sec value from gettimeofday() (it will show GMT)
> gmtime() will fail to work correctly when handed the time\_t from time() (it will show local time since time() is returning an incorrect time\_t value)
> 
> \--------------------
> 
> I'm not sure how this can be fixed since it appears to be an issue in code outside of this source tree.
> It seems like until it is fixed, users using the time code with timezone offsets need to know and understand the issues.
> Until it gets fixed, perhaps some notes and big warnings could be placed in the comments in the 
> NTP-TZ-DST.ino demo sketch

--- bill

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 5:12pm UTC](https://forum.arduino.cc/t/esp8266-daylight-savings-time-dst-not-working/514213/5 "2021-05-06T17:12:53Z")

</div>


