Future time not setable at Time.setTime()?

Hey Everyone!

I struggle with “setTime” function. I guess I can’t set a unix value which is in the future?
I just found the sentence “Set the system time to the given timestamp.” in the reference.
I’ve attached a piece of my code.When I have the condition (menuMove=2) everything works correctly!
Hope anybody knows more.
Code_TCK

It's usually better to post the actual code and not a screenshot since the former could just be taken and copy/pasted into a test project :wink:

Nice to know that, but it might be more enlightnening what exactly happens when it's not working.

How would the device know whether the time you give it is actually in the future, for it it's just a number as any other number would be.

Hi ScruffR,
thanks for your notice :slight_smile:. I’ll do it next time.
If the unix value is higher than the current Time.now() (just a guess), the device jumps back to the start menu without setting the new time.

This works just fine for me

void setup() {
}

void loop() {
  static uint32_t ms = 0;
  
  if (!digitalRead(BTN)) {
    time_t now = Time.now();
    Time.setTime(now + 3600);
    delay(500);
  }
  
  if (millis() - ms < 1000) return;
  ms = millis();
  
  Serial.println(Time.timeStr());
}

Each time you press the MODE/SETUP button the printed time will go one hour forward as expected.

1 Like

Thank you scruffR. Finally I found my mistake. There was another function which worked with the time values. I guess this post can be closed.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.