2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00
2021-06-02 02:19:01 +08:00

Timing and Time

Introduction

The timing and time module provides APIs for managing the system time.

Figure 1 Subsystem architecture

Directory Structure

/base/miscservices/time
├── etc                      # Process configuration files
├── figures                  # Architecture diagram
├── interfaces               # APIs for external systems and applications
│   └── kits                # APIs
├── profile                  # System service configuration files
└── services                 # Service implementation

Usage

Available JS APIs

Table 1 Major functions of systemTime

Function

Description

function setTime(time : number) : Promise<boolean>

Sets the system time and uses a Promise to return the execution result.

function setTime(time : number, callback : AsyncCallback<boolean>) : void

Sets the system time and uses a callback to return the execution result.

Sample Code

Example fo using systemTime

// Import the module.
import systemTime from '@ohos.systemTime';

// Set the system time asynchronously with a Promise.
var time = 1611081385000;
systemTime.setTime(time)
    .then((value) => {
        console.log(`success to systemTime.setTime: ${value}`);
    }).catch((err) => {
        console.error(`failed to systemTime.setTime because ${err.message}`);
    });

// Set the system time asynchronously with a callback.
var time = 1611081385000;
systemTime.setTime(time, (err, value) => {
    if (err) {
        console.error(`failed to systemTime.setTime because ${err.message}`);
        return;
    }
    console.log(`success to systemTime.setTime: ${value}`);
});

Repositories Involved

Misc services subsystem

miscservices_time

S
Description
Timing and time module | 时间和定时组件
Readme 1.5 MiB
Languages
C++ 70.2%
JavaScript 29.6%
C 0.2%