Skip to main content
Version: 8.2.2

time

The sos.management.time API groups together methods for working with the system time.

Time Management Capabilities
CapabilityDescription
SET_TIMEIf the device can set the system time.
SET_TIMEZONEIf the device can set the system timezone.
GET_TIMEZONEIf the device can get the system timezone.
NTP_TIMEIf the device can set the NTP server and system timezone.

If you want to check if the device supports those capabilities, use sos.management.supports().

Methods

get()

The get() method returns the currently set time from the device.

get(): Promise<IGetTime>;

Return value

A promise that resolves to the current time with timezone.

Possible errors

If the time cannot be retrieved.

Example

const currentTime = await sos.management.time.get();
console.log(`Current time is: ${currentTime.currentDate} in timezone ${currentTime.timezone}`);

setManual(dateTime, timezone)

The setManual() method sets the system time and the system timezone and disables NTP server settings.

Setting NTP server and timezone has side effects
  • Tizen: After calling this API, display Reboots! Tizen has a limited set of available timezones. Read more here.
  • RaspberryPi: After calling this API, RPi Reboots the backend server, which can take up to 60 seconds! During the reboot, no JS API is available. Always wait for Promise resolution.
setManual(dateTime: DateTime, timezone: string): Promise<void>;

Params

NameTypeRequiredDescription
dateTimeDateTime
Yes
The date and time to set.
timezonestring
Yes
The timezone to set.

Return value

A promise that resolves when the time is successfully set.

Possible errors

  • If dateTime is not a valid Date or DateTime object.
  • If timezone is not a valid string.
  • If the time cannot be set.

Example

// Set the system time to 2023-10-01T12:00:00 in Europe/Prague timezone
const dateTime = {
year: 2023,
month: 10,
day: 1,
hour: 12,
minute: 0,
second: 0,
}
await sos.management.time.setManual(dateTime, 'Europe/Prague');

setNTP()

The setNTP() method sets the NTP server and the system timezone.

Setting NTP server and timezone has side effects
  • Tizen / WebOS: After calling this API, display Reboots! Tizen has a limited set of available timezones. Read more here.
  • RaspberryPi: After calling this API, RPi Reboots the backend server, which can take up to 60 seconds! During the reboot, no JS API is available. Always wait for Promise resolution.
setNTP(ntpServer: string, timezone: string): Promise<void>;

Params

NameTypeRequiredDescription
ntpServerstring
Yes
The NTP server to set.
timezonestring
Yes
The timezone to set.

Return value

A promise that resolves when the NTP server and timezone are successfully set.

Possible errors

  • If ntpServer is not a valid string.
  • If timezone is not a valid string.
  • If the NTP server and timezone cannot be set.

Example

// Set the NTP server to `pool.ntp.org` and timezone to `Europe/Prague`
await sos.management.time.setNTP('pool.ntp.org', 'Europe/Prague');

set()

Deprecated

This method was deprecated. Use setManual(dateTime, timezone) instead.

set(currentDate: Date, timezone: string): Promise<void>;

setManual(currentDate, timezone)

Deprecated

This method was deprecated. Use setManual(dateTime, timezone) instead.

setManual(currentDate: Date, timezone: string): Promise<void>;

API Example

import { sos } from '@signageos/front-applet';

void sos.onReady(async () => {
const { currentDate, timezone, ntpServer } = await sos.management.time.get();
console.log({ currentDate, timezone, ntpServer });

// Set the time without a ntp server
await sos.management.time.setManual(
{
year: 2025,
month: 5,
day: 23,
hour: 13,
minute: 0,
second: 0,
},
'Europe/Amsterdam',
);

// Set the time with a ntp server
await sos.management.time.setNTP('pool.ntp.org', 'Europe/Amsterdam');
});