---
title: systemtime
slug: develop/systemtime
docTags: 
createdAt: 2025-03-27T16:56:35.112Z
---

The *systemtime&#xA0;*&#x6F;bject provides the ability to read and write the time stored in the real-time clock (RTC). It can also be used to read and write the time-zone setting.

**systemtime IDL**

```javascript
interface SystemTime {
    Promise<void> setDate(Date date);
    Promise<void> setTimeZone(String timezone_string); // requires reboot
    Promise<String> getTimeZone();
    Promise<LastNetworkTimeResult> lastNetworkTimeResult();
    void addEventListener(String type, NetworkTimeEventCallback callback);
    void removeEventListener(String type, NetworkTimeEventCallback callback);
};

interface LastNetworkTimeResult {
    readonly attribute long successTimestamp;
    readonly attribute long attemptTimestamp;
    readonly attribute String failureReason;
};
```

## Object Creation

To create a *systemtime* object, first load the `brightsign/systemtime` module using the `require()` method. Then create an instance of the *systemtime* class.

```javascript
var systemTimeClass = require("@brightsign/systemtime");
var systemTime = new systemTimeClass();
```

## SystemTime

Use this interface to set the date and time zone and retrieve network time data.

### Events

`[EventHandler] networktimeevent`:  An event that is is raised when the player attempts to update its clock via the network. Use the `addEventListener()` method to listen for this event. Results are returned as a *NetworkTimeEvent&#xA0;*&#x69;nterface.

### Methods

**setDate()**

```javascript
Promise<void> setDate(Date date)
```

Specifies a new time for the RTC using the current time zone.

**setTimeZone()**

```javascript
Promise<void> setTimeZone(String timezone_string)
```

Specifies a new time-zone setting for the player (supported time zones are listed on [this page](docId\:HWR0ZojGTZxXnUHDLHlf9)). Alternatively, a POSIX-formatted time zone can be applied by appending a `POSIX:` value to the beginning of the string. This method requires a reboot to go into effect.

**getTimeZone() As Promise\<String>**

```javascript
Promise<String> getTimeZone()
```

Returns the current time-zone setting of the player. A `POSIX:` value is appended to the beginning of the string if the time zone has been set using the POSIX format.

**lastNetworkTimeResult()**

```javascript
Promise<LastNetworkTimeResult> lastNetworkTimeResult()
```

Returns a LastNetworkTimeResult interface containing information about the last attempt to set the time via the network.

## LastNetworkTimeResult

This interface contains information about the last attempt to set the time via the network. It contains the following read-only attributes:

- `successTimestamp` <font color="#6554c0">long</font>: A value indicating when (in seconds) the clock was last set successfully via the network. This value is zero if the clock has never been set successfully via the network.
- `attemptTimestamp` <font color="#6554c0">long</font>:  A value indicating when (in seconds) the last attempt was made to set the clock via the network. This value is zero if no attempt has been made yet.
- `failureReason` <font color="#6554c0">String</font>:  If the last attempt to set the clock via the network failed, this string will contain an error message. If the last attempt was successful, this string will be empty.

## NetworkTimeEvent

This interface is returned by the event listener for `networktimeevent`. It contains the following read-only attributes:

- `success` <font color="#6554c0">bool:</font> A flag indicating whether the last attempt to set the time via the network was successful or not.
- `reason` <font color="#6554c0">string</font>: An error message that will be included if the last attempt failed.

## Example

```javascript
var SystemTimeClass = require("@brightsign/systemtime");
var systemTime = new SystemTimeClass();

//Set the date to 2018
var date = new Date();
date.setFullYear(2018);
systemTime.setDate(date);

//Set the time zone
systemTime.setTimeZone("PST")

//Listen for a network time event
systemTime.addEventListener("networktimeevent",
    function(data) {
        console.log("Last network update:" + JSON.stringify(data.detail));
    });
```

