MDN may have intermittent access issues April 18 13:00 - April 19 01:00 UTC. See whistlepig.mozilla.org for all notifications.

mozilla
Your Search Results

    Time and Clock

    Non-standard
    This feature is not on a current W3C standards track, but it is supported on the Firefox OS platform. Although implementations may change in the future and it is not supported widely across browsers, it is suitable for use in code dedicated to Firefox OS apps.

    This API is available on Firefox OS for internal applications only.

    Summary

    The Time/Clock API is a simple way to change the system time.

    Overview

    The API is accessed through navigator.mozTime and returns a MozTimeManager object which exposes a single set() method.

    The set() method is used to actually change the time of the system. It accepts a number or a Date object as parameter. If a number is provided, it represents the number of milliseconds since midnight UTC January 1, 1970.

    Each time the time is changed, an event is fired. This event can be capture at the window object level by using the addEventListener method (using the moztimechange event name) or by attaching an event handler to the window.onmoztimechange property.

    Note: If you want to change the timezone of your device, you have to use the Settings API.

    Example

    function setTime(time) {
      navigator.mozTime.set(time);
    }
    
    window.addEventListener('moztimechange', function () {
      console.log('Time has changed');
    });
    
    setTime(new Date());
    

    Specification

    Not part of any specification

    Document Tags and Contributors

    Contributors to this page: SpencerG, Ephemera, Jeremie, justinpotts, kscarfone, teoli
    Last updated by: kscarfone,