You are reading a single comment by @DaveNI and its replies. Click here to read the full conversation.
  • Espruino has a real time clock which accurately records the elapsed time since the device was started (powered up). This can be retrieved in ms using getTime().

    There is also a Date class which handles dates & times (calendar, years, months, days, hours, mins etc.)

    These are tied together using the Clock class to manage the current date/time. An instance of this class needs to be instantiated/initialised every time the device is restarted as shown below:

      var Clock = require("clock").Clock;
      var clk=new Clock(2014,4,15,23,45,0,0);   // Initialise with specific date
      var clk=new Clock("Jun 23, 2014 12:18:02");   // ... or Initialise with specific date
    

    You can then retrieve the current date/time as follows:

        var currentDatetime = clk.getDate(); 
    

    See http://www.espruino.com/Reference#Date , http://www.espruino.com/clock and http://www.espruino.com/Clocks for more details.

About

Avatar for DaveNI @DaveNI started