[Solved/Fixed] Time.now() in setup() gives bad time after power on

In our project we want to report the time that the core was started. In setup() we made a call to Time.now() and stashed the value away for later use.

This works great when the core is started from the reset button. However, when the core is actually power cycled the reported time is very small. Like 2 or 3 instead of a good epoc time.

My guess is that where ever the Time library gets the value, it isn’t ready so quickly after a power up.

We’ll deal with this in our project, but I wanted to put it out here for others.


@JSchrempp, take a lot at this topic:


@peekay123, You pointed me back to my same topic. Maybe you meant to include a different link?

BTW, I now see that after a power on Time.now() takes about 2 seconds to become stable.


I hate my ipad sometimes :stuck_out_tongue:

The correct link is:

1 Like

I’ve added this code to our setup() function. It seems to do the trick.

    resetTime = Time.now();        // the the current time = time of last reset
} while (resetTime < 1000000 && millis() < 20000); // wait for a reasonable epoc time, but not longer than 20 seconds


this seemed to do the trick for me

  if(CurrentTime < Time.now()){
      CurrentTime == Time.now();