Clock Module

This clock (About Modules) module implements a Clock for Espruino. It uses the date module to store both time and date.

How to use the module:

  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 from a string

  // every time the button is pressed, print the current time..
  setWatch(function() {
    var d1=clk.getDate(); 
    print(d1.toString()); // prints "Thu May 15 2014 23:45:05" 
  }, BTN, { edge : "rising", repeat : true, debounce : 10 } );

  // You can also update the current time
  clk.setClock(Date.parse("Jun 23, 2014 12:18:02"));

Reference

/* Clock constructor. Arguments to this
are in exactly the same form as those
to the built-in Date constructor.
*/
function () { ... }

// setClock(milliseconds since 1/1/1970)
Clock.prototype.setClock = function (ms) { ... }

/* Return the current clock time, as a date object.  We calculate the number
 of milliseconds since setClock or the constructor was called, and 
 add this to the date that was set at that time.
*/
Clock.prototype.getDate = function () { ... }

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.