HarmonyOS 如何获取本地时区?

如题:HarmonyOS 如何获取本地时区?

阅读 691
1 个回答

获取系统时区可以使用:

systemDateTime.getTimezoneSync10+   getTimezoneSync(): string 

参考示例如下:

import { BusinessError } from '@kit.BasicServicesKit';

try {
  let timezone = systemDateTime.getTimezoneSync();
} catch (e) {
  let error = e as BusinessError;
  console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
}

参考指南链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-date-time-V5\#systemdatetimegettimezone

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-i18n-V5\#timezone

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进