同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
说明: 从 API Version 7 开始支持。
import systemTime from '@ohos.systemTime';
setTime(time : number, callback : AsyncCallback<void>) : void
设置系统时间,需要ohos.permission.SET_TIME权限。
参数:
示例:
// time对应的时间为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));
});
setTime(time : number) : Promise<void>
设置系统时间,需要ohos.permission.SET_TIME权限。
参数:
返回值:
示例:
// time对应的时间为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));
});
setDate(date: Date, callback: AsyncCallback<void>): void
设置系统日期,需要ohos.permission.SET_TIME权限。
参数:
示例:
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));
});
setDate(date: Date): Promise<void>
设置系统日期,需要ohos.permission.SET_TIME权限。
参数:
返回值:
示例:
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));
});
setTimezone(timezone: string, callback: AsyncCallback<void>): void
设置系统时区,需要ohos.permission.SET_TIME_ZONE权限。
参数:
示例:
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));
});
setTimezone(timezone: string): Promise<void>
设置系统时区,需要ohos.permission.SET_TIME_ZONE权限。
参数:
返回值:
示例:
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));
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。