mirror of
https://github.com/openharmony/miscservices_time.git
synced 2026-07-19 12:02:04 -04:00
OpenHarmony-2.2-Beta2
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
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
Description
Languages
C++
70.2%
JavaScript
29.6%
C
0.2%