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:
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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:
You can then retrieve the current date/time as follows:
See http://www.espruino.com/Reference#Date , http://www.espruino.com/clock and http://www.espruino.com/Clocks for more details.