Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setTimeZone doesn't seem to be working correctly #6

Closed
buelowp opened this issue Apr 15, 2020 · 7 comments
Closed

setTimeZone doesn't seem to be working correctly #6

buelowp opened this issue Apr 15, 2020 · 7 comments

Comments

@buelowp
Copy link

buelowp commented Apr 15, 2020

This is the built on the latest Arduino IDE. I've got the following which doesn't seem to be working correctly.

    DateTime.setServer("pool.ntp.org");
    
    DateTime.begin();

    if (!DateTime.isTimeValid()) {
        Serial.println("Failed to get time from server.");
    }
    else {
        DateTime.setTimeZone(currentTimeZone());
        Serial.print("Setting timezone to ");
        Serial.println(currentTimeZone());
    }

I print in loop() with the following

void loop() 
{
    Serial.println(DateTime.toString().c_str());
    Serial.println(DateTime.toUTCString());
    delay(5000);
}

Where currentTimeZone is a function I have to that returns an integer timezone. Time must be set first, it needs to know the month and year. When I call DateTime.setTimeZone(), GMT is changed and in the wrong direction.

IP address: 172.24.1.56
Setting timezone to -5
2020-04-15 15:19:05
Wed, 15 Apr 2020 20:19:05 GMT

Local time when this printed was 10:15:05 AM. If I don't set the timezone, both are the same

IP address: 172.24.1.56
Setting timezone to -5
2020-04-15 15:24:18
Wed, 15 Apr 2020 15:24:18 GMT

Local time when this was printed was 10:24:18

Finally, if I pass it a positive timezone (5 instead of -5)

IP address: 172.24.1.56
Setting timezone to 5
2020-04-15 15:25:55
Wed, 15 Apr 2020 10:25:55 GMT

Local time when this was printed was 10:25:55

I'm using version 0.2.0 in the Arduino IDE.

*** Edit
I added a true/false check on the setTimeZone() function, and it returns true.

@rin67630
Copy link

rin67630 commented May 3, 2020

Same thing here.
I have set the time zone to -1 (Paris) I get the asian time, 6 hours ahead...
The settings of the time zone seem to be completely ignored.
void setupDateTime() { // DateTime.begin(15 * 1000); DateTime.setServer("nl.pool.ntp.org"); DateTime.setTimeZone(-1); DateTime.begin(); if (!DateTime.isTimeValid()) { Serial.println("Failed to get time from server."); } }

Hint:
On an ESP32 the time zone is working correctly, The reported time zone from p.getTimeZone() is always correctly reported as I have set it.
But on an ESP8266 workaround with adding seconds (computed from the time zone settings) is failing: the time given ist just always the asian one.

@buelowp
Copy link
Author

buelowp commented May 3, 2020

Mine was failing on an ESP32 though, so it's not processor specific.

@fusionstream
Copy link

Same issue on an ESP8266 on a Wemos D1 Mini Pro. As a workaround, I just inverted the timezone. For +5, I set it to -5

@xfdr0805
Copy link

xfdr0805 commented Jun 4, 2020

me too
DateTime.setServer(ntpServer);
DateTime.begin(15 * 1000);

DateTime.setTimeZone(8);//not work

DateTime.begin();

String str = " >>NTP对时成功," + DateTime.toString();
draw_chinese_font(0, 80, str.c_str(), ILI9341_RED);
if (!DateTime.isTimeValid()) {
Serial.println("Failed to get time from server.");
}

time_t t = DateTime.now() + 8 * 3600;

DateTime.setTime(t);
setTime(t);

@xfdr0805
Copy link

xfdr0805 commented Jun 4, 2020

sloved:
esp8266/Arduino#7319

@mcxiaoke
Copy link
Owner

ESP8266 does not support timezone, it just add timeZone * 3600 seconds to original timestamp. maybe esp8266/Arduino#7319 fixed this.

@mcxiaoke
Copy link
Owner

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants