pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble JavaScript API

  • Pebble C API
  • Pebble JavaScript API
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • CanvasRenderingContext2D
    • TextMetrics
    • fillStyle
    • Canvas
    • strokeStyle
    • canvas
    • lineWidth
    • font
    • textAlign
    • clearRect
    • fillRect
    • strokeRect
    • fillText
    • measureText
    • beginPath
    • closePath
    • moveTo
    • lineTo
    • arc
    • rect
    • fill
    • stroke
    • save
    • restore
    • rockyFillRadial
  • console
    • log
    • warn
    • error
  • Date
    • toLocaleString
    • toLocaleTimeString
    • toLocaleDateString
  • rocky
    • RockyPostMessageErrorCallback
    • RockyPostMessageConnectedCallback
    • WatchInfo
    • watchInfo
    • RockyMemoryPressureCallback
    • RockyPostMessageDisconnectedCallback
    • UserPreferences
    • RockyDrawCallback
    • RockyMessageCallback
    • RockyTickCallback
    • userPreferences
    • on
    • addEventListener
    • removeEventListener
    • off
    • postMessage
    • requestDraw

Date

Creates a JavaScript Date instance that represents a single moment in time. Date objects are based on a time value that is the number of milliseconds since 1 January, 1970 UTC.

var d = new Date();

We fully implement standard JavaScript Date functions, such as: getDay(), getHours() etc.

For full Date documentation see: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date

Locale Date Methods

The locale date methods (toLocaleString, toLocaleTimeString and toLocaleDateString) are currently limited in their initial implementation.

Available options:

hour12

Use 12-hour time (as opposed to 24-hour time). Possible values are true and false; the default is locale dependent (Pebble setting).

weekday

The representation of the weekday. Possible values are "narrow", "short", "long".

year

The representation of the year. Possible values are "numeric", "2-digit".

month

The representation of the month. Possible values are "numeric", "2-digit", "narrow", "short", "long".

day

The representation of the day. Possible values are "numeric", "2-digit".

hour

The representation of the hour. Possible values are "numeric", "2-digit".

minute

The representation of the minute. Possible values are "numeric", "2-digit".

second

The representation of the second. Possible values are "numeric", "2-digit".

Please note that locale based date and time functions have the following limitations at this time:

  • You cannot manually specify a locale, it's automatically based upon the current device settings. Locale is optional, or you can specify undefined.

    console.log(d.toLocaleDateString());

  • Only a single date/time value can be requested in each method call. Do NOT request multiple options. e.g. {hour: 'numeric', minute: '2-digit'}

    console.log(d.toLocaleTimeString(undefined, {hour: 'numeric'}));

Methods

Date.toLocaleString(locale, options)

This method returns a string with a language sensitive representation of this date object.

d.toLocaleString();

Parameters

String locale

(Optional) The name of the locale.

Object options

(Optional) Only a single option is currently supported.

Date.toLocaleTimeString(locale, options)

This method returns a string with a language sensitive representationof the date portion of this date object.

d.toLocaleTimeString(undefined, {hour: 'numeric'});

Parameters

String locale

(Optional) The name of the locale.

Object options

(Optional) Only a single option is currently supported.

Date.toLocaleDateString(locale, options)

This method returns a string with a language sensitive representationof the time portion of this date object.

d.toLocaleDateString(undefined, {weekday: 'long'});

Parameters

String locale

(Optional) The name of the locale.

Object options

(Optional) Only a single option is currently supported.

Need some help?

Methods

  • toLocaleString
  • toLocaleTimeString
  • toLocaleDateString

Examples

  • Watchface Tutorial
  • Memory Pressure

Web API by Mozilla Contributors is licensed under CC-BY-SA 2.5.

Getting Help

Do you need some help understanding the something on this page?

You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!