1/** 2 * @file Describe the file 3 * Copyright (c) 2023 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17export const HOURS_PER_DAY = 24; 18 19export const MINUTES_PER_HOUR = 60; 20 21export const SECONDS_PER_MINUTE = 60; 22 23export const MILLS_PER_SECOND = 1000; 24 25export const MILLS_PER_MINUTE = MILLS_PER_SECOND * 60; 26 27export const MILLS_PER_HOUR = MILLS_PER_MINUTE * 60; 28 29export const MILLS_PER_DAY = MILLS_PER_HOUR * 24; 30 31export const MILLS_PER_WEEK = MILLS_PER_DAY * 7; 32 33export function getMinutesByMills(date: Date, mills: number): number { 34 if (date === null || date === undefined) { 35 date = new Date(); 36 } 37 date.setTime(mills); 38 return date.getHours() * MINUTES_PER_HOUR + date.getMinutes(); 39} 40 41/** 42 * 获取当前设备所在时区与UTC时区时间差值的毫秒数 43 */ 44export function getCurrentTimeZoneMillisecond(date: Date): number { 45 return -date.getTimezoneOffset() * MILLS_PER_MINUTE; 46}