I'm a little confused...
Is 'new Date()' supposed to return the current DateTime like 'Thu Nov 07 2019 17:36:22 GMT+0200'?
Somehow I'm getting 'Thu Jan 1 1970 02:46:57 GMT+0000'
Am I missing something?
There is a checkbox in IDE settings that seeds date and time from your IDE machine on code upload to Espruino board.
Ok, I can now see the correct date and time, but, my tests shows that if I'm using onInite function when the board is connected to an external power source the date goes back to 1970, is that mean that I need to manage getting the current datetime from the internet or whatever so the board can continue from there or there is another better solution for boards that does not connect to the internet like Puck.js etc. ?
Yes, removing power from it resets the clock.
If you keep the Puck powered, it will remember the time. And will last a long time on battery.
Or you can use an external RTC with it's own battery, and read time from the RTC on startup.
Or you can set the time with setTime when you connect to it. You can do it automatically with some coding, if you connect to it with BLE from your computer of phone.
If you're worried about losing the time, the best bet is to ensure that you have some backup battery always connected to the device via a diode.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem