Clock API
chevron down
 

Clock API

Variable: clock

Type: Clock

The Clock API provides functionality related to the real-time clock of the device, mainly for the purpose of clock face applications.

This API provides a reliable update mechanism which is automatically deactivated when the device display is off.

import clock from "clock";

clock.granularity = "minutes";
clock.ontick = (evt) => {
   console.log(evt.date.toTimeString());
}

Find out more about this API in the Clock Face Guide

Interface: Clock

The Clock object provides functionality related to the real-time clock of the device, mainly for the purpose of clock face applications.

NOTE: Use the standard JavaScript Date API to access the actual clock time.

Properties

granularity

"off" or "seconds" or "minutes" or "hours"

Granularity at which a tick event should be emitted.

The possible values are:

  • "off": do no emit any tick event (default).
  • "seconds": emit a tick event when the clock's 'second' hand ticks.
  • "minutes": emit a tick event when the clock's 'minute' hand ticks.
  • "hours": emit a tick event when the clock's 'hour' hand ticks.
ontick

((this: Clock, event: TickEvent) => any) or undefined

Event handler for the tick event emitted by the clock.

Interface: TickEvent

Event that is emitted by the Clock object.

Properties

date

Date

The current time when the event was emitted.

The values returned by date.getMilliseconds(), date.getSeconds(), date.getMinutes() and date.getHours() are consistent with the clock's granularity property:

  • If granularity is "seconds", date.getMilliseconds() returns 0.
  • If granularity is "minutes", date.getSeconds() and date.getMilliseconds() return 0.
  • If granularity is "hours", date.getMinutes(), date.getSeconds() and date.getMilliseconds() return 0.
readonly defaultPrevented

boolean

Set to true when the default handling was prevented

readonly target

EventTarget or undefined

Target of the event

readonly type

string

Type of the event