The **systemDateTime** module provides system time and time zone features. You can use the APIs of this module to set and obtain the system time and time zone.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: The time to return is in nanoseconds.<br>- **false**: The time to return is in milliseconds.|
| callback | AsyncCallback<number> | Yes | Callback used to return the time elapsed since the Unix epoch. |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: The time to return is in nanoseconds.<br>- **false**: The time to return is in milliseconds.|
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: The time to return is in nanoseconds.<br>- **false**: The time to return is in milliseconds.|
| callback | AsyncCallback<number> | Yes | Callback used to return the time.|
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: The time to return is in nanoseconds.<br>- **false**: The time to return is in milliseconds.|
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: The time to return is in nanoseconds.<br>- **false**: The time to return is in milliseconds.|
| callback | AsyncCallback<number> | Yes | Callback used to return the time. |
**Example**
```js
try{
systemDateTime.getRealTime(true,(error,time)=>{
if(error){
console.info(`Failed to get real time. message:${error.message}, code:${error.code}`);
return;
}
console.info(`Succeeded in getting real time : ${time}`);
});
}catch(e){
console.info(`Failed to get real time. message:${e.message}, code:${e.code}`);
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: The time to return is in nanoseconds.<br>- **false**: The time to return is in milliseconds.|
| callback | AsyncCallback<string> | Yes | Callback used to return the system time zone. For details, see [Supported System Time Zones](#supported-system-time-zones).|
**Example**
```js
try{
systemDateTime.getTimezone((error,data)=>{
if(error){
console.info(`Failed to get timezone. message:${error.message}, code:${error.code}`);
return;
}
console.info(`Succeeded in get timezone : ${data}`);;
});
}catch(e){
console.info(`Failed to get timezone. message:${e.message}, code:${e.code}`);
}
```
## systemDateTime.getTimezone
getTimezone(): Promise<string>
Obtains the system time zone. This API uses a promise to return the result.
The **systemTime** module provides system time and time zone features. You can use the APIs of this module to set and obtain the system time and time zone.
...
...
@@ -12,7 +12,7 @@ The **systemTime** module provides system time and time zone features. You can u
Obtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime).
Obtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime-1).
Obtains the time elapsed since the Unix epoch. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime-2).
Obtains the time elapsed since system startup, excluding the deep sleep time. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime).
Obtains the time elapsed since system startup, excluding the deep sleep time. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime-1).
Obtains the time elapsed since system startup, excluding the deep sleep time. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime-2).
Obtains the time elapsed since system startup, including the deep sleep time. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime).
Obtains the time elapsed since system startup, including the deep sleep time. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime-1).
Obtains the time elapsed since system startup, including the deep sleep time. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime-2).
Obtains the current system date. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getDate](./js-apis-system-date-time.md#systemdatetimegetdate).
@@ -406,21 +498,29 @@ Obtains the current system date. This API uses an asynchronous callback to retur
**Example**
```js
systemTime.getDate((error,data)=>{
if(error){
console.error(`Failed to get system date. Cause:`+JSON.stringify(error));
return;
}
console.log(`Succeeded in getting system date. Data:`+JSON.stringify(data));
});
try{
systemTime.getDate((error,date)=>{
if(error){
console.info(`Failed to get date. message:${error.message}, code:${error.code}`);
return;
}
console.info(`Succeeded in get date : ${date}`);;
});
}catch(e){
console.info(`Failed to get date. message:${e.message}, code:${e.code}`);
}
```
## systemTime.getDate<sup>8+</sup>
## systemTime.getDate<sup>(deprecated)</sup>
getDate(): Promise<Date>
Obtains the current system date. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getDate](./js-apis-system-date-time.md#systemdatetimegetdate-1).
Obtains the system time zone. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getTimezone](./js-apis-system-date-time.md#systemdatetimegettimezone).
@@ -517,21 +633,29 @@ Obtains the system time zone. This API uses an asynchronous callback to return t
**Example**
```js
systemTime.getTimezone((error,data)=>{
if(error){
console.error(`Failed to get system time zone. Cause:`+JSON.stringify(error));
return;
}
console.log(`Succeeded in getting system time zone. Data:`+JSON.stringify(data));
});
try{
systemTime.getTimezone((error,data)=>{
if(error){
console.info(`Failed to get timezone. message:${error.message}, code:${error.code}`);
return;
}
console.info(`Succeeded in get timezone : ${data}`);;
});
}catch(e){
console.info(`Failed to get timezone. message:${e.message}, code:${e.code}`);
}
```
## systemTime.getTimezone<sup>8+</sup>
## systemTime.getTimezone<sup>(deprecated)</sup>
getTimezone(): Promise<string>
Obtains the system time zone. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getTimezone](./js-apis-system-date-time.md#systemdatetimegettimezone-1).
| type | number | Yes | Timer type.<br>**1**: CPU time type. The start time of the timer cannot be later than the current system time.<br>**2**: wakeup type.<br>**4**: exact type.<br>**5**: idle type (not supported currently).|
| repeat | boolean | Yes | Whether the timer is a repeating timer. The value **true** means that the timer is a repeating timer, and **false** means that the timer is a one-shot timer. |
| interval | number | No | Repeat interval. For a repeating timer, the value must be greater than 5000 ms. For a one-shot timer, the value is **0**.|
| wantAgent | [WantAgent](js-apis-wantAgent.md) | No | **WantAgent** object of the notification to be sent when the timer expires. (An application MainAbility can be started, but not a Service ability.)|
| callback | number | Yes | Callback used to return the timer ID. |
| type | number | Yes | Timer type.<br>**1**: CPU time type. (The start time of the timer cannot be later than the current system time.)<br>**2**: wakeup type.<br>**4**: exact type.<br>**8**: idle type (not supported currently).|
| repeat | boolean | Yes | Whether the timer is a repeating timer. The value **true** means that the timer is a repeating timer, and **false** means that the timer is a one-shot timer. |
| interval | number | No | Repeat interval. For a repeating timer, the value must be greater than 5000 ms. For a one-shot timer, the value is **0**.|
| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | No | **WantAgent** object of the notification to be sent when the timer expires. (An application MainAbility can be started, but not a Service ability.)|
| callback | number | Yes | Callback used to return the timer ID. |