# Setting the System Time
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>The APIs of this module are supported since API version 7.
## Modules to Import
```
import systemTime from '@ohos.systemTime';
```
## systemTime.setTime
setTime\(time : number, callback : AsyncCallback\) : void
Set the system time. You must have the ohos.permission.SET\_TIME permission. The value is returned in callback mode.
- Parameters
Name
Type
Mandatory
Description
time
number
Yes
Timestamp to set, in milliseconds
callback
AsyncCallback<void>
Yes
Callback used to process the received return value
- Example
```
// Set the date and time to 2021-01-20 02:36:25.
var time = 1611081385000;
systemTime.setTime(time, (error, data) => {
if (error) {
console.error(`failed to systemTime.setTime because ` + JSON.stringify(error));
return;
}
console.log(`success to systemTime.setTime: ` + JSON.stringify(data));
});
```
## systemTime.setTime
setTime\(time : number\) : Promise
Set the system time. You must have the ohos.permission.SET\_TIME permission. The value is returned in promise mode.
- Parameters
Name
Type
Mandatory
Description
time
number
Yes
Timestamp to set, in milliseconds
- Return values
Type
Description
Promise<void>
Callback returned in promise mode
- Example
```
// Set the date and time to 2021-01-20 02:36:25.
var time = 1611081385000;
systemTime.setTime(time).then((data) => {
console.log(`success to systemTime.setTime: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`failed to systemTime.setTime because ` + JSON.stringify(error));
});
```
## systemTime.setDate
setDate\(date: Date, callback: AsyncCallback\): void
Set the system date. You must have the ohos.permission.SET\_TIME permission. The value is returned in callback mode.
- Parameters
Name
Type
Mandatory
Description
date
Date
Yes
Target date
callback
AsyncCallback<void>
Yes
Callback used to process the received return value
- Example
```
var data = new Date("October 13, 2020 11:13:00");
systemTime.setDate(data,(error, data) => {
if (error) {
console.error('SystemTimePlugin setDate failed because ' + JSON.stringify(error));
return;
}
console.info('SystemTimePlugin setDate success data : ' + JSON.stringify(data));
});
```
## systemTime.setDate
setDate\(date: Date\): Promise
Set the system date. You must have the ohos.permission.SET\_TIME permission. The value is returned in promise mode.
- Parameters
Name
Type
Mandatory
Description
date
Date
Yes
Target date
- Return values
Type
Description
Promise<void>
Callback returned in promise mode
- Example
```
var data = new Date("October 13, 2020 11:13:00");
systemTime.setDate(data).then((value) => {
console.log(`SystemTimePlugin success to systemTime.setDate: ` + JSON.stringify(value));
}).catch((error) => {
console.error(`SystemTimePlugin failed to systemTime.setDate because: ` + JSON.stringify(error));
});
```
## systemTime.setTimezone
setTimezone\(timezone: string, callback: AsyncCallback\): void
Set the system time zone. You must have the ohos.permission.SET\_TIME\_ZONE permission. The value is returned in callback mode.
- Parameters
Name
Type
Mandatory
Description
timezone
string
Yes
System time zone
callback
AsyncCallback<void>
Yes
Callback used to process the received return value
- Example
```
systemTime.setTimezone('Asia/Shanghai', (error, data) => {
if (error) {
console.error('SystemTimePlugin setTimezone failed because ' + JSON.stringify(error));
return;
}
console.info('SystemTimePlugin setTimezone success data : ' + JSON.stringify(data));
});
```
## systemTime.setTimezone
setTimezone\(timezone: string\): Promise
Set the system time zone. You must have the ohos.permission.SET\_TIME\_ZONE permission. The value is returned in promise mode.
- Parameters
Name
Type
Mandatory
Description
timezone
string
Yes
System time zone
- Return values
Type
Description
Promise<void>
Callback returned in promise mode
- Example
```
systemTime.setTimezone('Asia/Shanghai').then((data) => {
console.log(`SystemTimePlugin success to systemTime.setTimezone: ` + JSON.stringify(data));
}).catch((error) => {
console.error(`SystemTimePlugin failed to systemTime.setTimezone because: ` + JSON.stringify(error));
});
```