Working with DateTime

Posted on
  • Hi,

    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?

    Thanks
    Michael.

  • 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. ?

    Thanks,
    Michael.

  • 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.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Working with DateTime

Posted by Avatar for michael_101 @michael_101

Actions