When obtaining non-local time, you are advised to use the standard APIs in I18n.Calendar to obtain time and time zone information.
// code-linter.json5
{
"rules": {
"@performance/timezone-interface-check": "suggestion",
}
} import i18n from '@ohos.i18n'; let calendar = i18n.getCalendar(i18n.getSystemLocale()); calendar.setTimeZone(i18n.getTimeZone().getID());
import i18n from '@ohos.i18n';
let timeZone1 = '123';
let calendar1 = i18n.getCalendar(i18n.getSystemLocale());
calendar1.setTimeZone(timeZone1);
calendar1.get('zone_offset');
calendar1.get('dst_offset'); import i18n from '@ohos.i18n';
let timeZone1 = '123';
let calendar1 = i18n.getCalendar(i18n.getSystemLocale());
calendar1.setTimeZone(timeZone1);
// Alert: dst_offset is not obtained.
calendar1.get('zone_offset');
//calendar1.get('dst_offset'); import moment from '@hview/moment';
// Alert.
moment().utcOffset();
// Alert.
moment().utcOffset(120);
// Alert.
moment().utcOffset("+08:00");
// Alert.
moment().utcOffset(-5, true); plugin:@performance/all
For details about how to configure Code Linter check rules, see Code Linter.