Current Date #4200
Replies: 1 comment
-
Posted at 2014-11-01 by DaveNI 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. Posted at 2014-11-01 by Espruino_user_dk Ok so I will have to provide the current date & time at start up as a kind of calibration? With WiFi one can use a time provider I guess... Thank you Posted at 2014-11-02 by DaveNI Yes - that is exactly what I was planning to do. Numerous simple services exist e.g. http://www.timeapi.org/utc/now This should be easily integrated using http.get() see: http://www.espruino.com/Internet Posted at 2014-11-02 by @gfwilliams When you request a webpage from a webserver, the headers contain the current date and time - which can be parsed directly by 1v71 will have some changes so that it remembers the current time after a hard reset (only forgetting it when powered off). That should make keeping time a lot easier, as assuming you keep a battery connected it'll always remember the correct time once you've programmed it, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-11-01 by Espruino_user_dk
Hi
How do you achieve the current date and time? I have tried new Date(); but like this:
Thu Jan 1 1970 02:43:17 GMT+0000
Thanks...
Beta Was this translation helpful? Give feedback.
All reactions