# Set millis() after coming out of sleep

**URL:** <https://community.particle.io/t/set-millis-after-coming-out-of-sleep/54326>\
**Category:** Firmware\
**Created:** [January 22, 2020, 6:18pm UTC](https://community.particle.io/t/set-millis-after-coming-out-of-sleep/54326 "2020-01-22T18:18:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marshall](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@marshall](https://community.particle.io/u/marshall)\
**Post date:** [January 22, 2020, 6:18pm UTC](https://community.particle.io/t/set-millis-after-coming-out-of-sleep/54326/1 "2020-01-22T18:18:07Z")

</div>

Hi there,

I would like to know if it is possible to update/write to millis()?

psuedo code

var millis\_now = millis(); //say its 1234mS  
sleep(50sec);  
wakeup;  
//millis\_now is still 1234.  
//millis() is still 1234.  
millis() = millis() += (50\*1000)?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 22, 2020, 6:22pm UTC](https://community.particle.io/t/set-millis-after-coming-out-of-sleep/54326/2 "2020-01-22T18:22:08Z")

</div>

No that is not possible.  
If you want to do something similar you need an intermediate variable.

---

<div class="post-metadata">

**Author:** ![marshall](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@marshall](https://community.particle.io/u/marshall)\
**Post date:** [January 22, 2020, 7:52pm UTC](https://community.particle.io/t/set-millis-after-coming-out-of-sleep/54326/3 "2020-01-22T19:52:41Z")

</div>

yeah I thought that would be the case, its a real shame, as so much code relies on millis() and then if you sleep, everything breaks.

I think that this would be a great addition to 1.5.0…  
after coming out of sleep millis() is updated by the time that the unit was asleep. - albeit with the disclaimer that it is not that accurate. (+/- 1000mS) you would have to use the Time.now() to determine how long it slept for.

---

<div class="post-metadata">

**Author:** ![HEng](https://avatars.discourse-cdn.com/v4/letter/h/c77e96/32.png) [@HEng](https://community.particle.io/u/HEng)\
**Post date:** [January 25, 2020, 1:01am UTC](https://community.particle.io/t/set-millis-after-coming-out-of-sleep/54326/4 "2020-01-25T01:01:31Z")

</div>

I think this highlights that this is a thing you _should not be_ using `millis()` for.

`millis()` gives you a count of milliseconds of program run time since start, which is useful for short-ish timers and delays. Measuring very long times or times that exist in reference to the real world (like figuring out what time it is after a sleep) is what the `Time` library is for.

You don’t really want to be tempting the system with a `millis()` overflow, although it would be a nice bug-test feature.
