1/* 2 * Copyright (C) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16export default class DateTimeUtil { 17 getTime(): string { 18 const DATETIME = new Date(); 19 return this.concatTime(DATETIME.getHours(), DATETIME.getMinutes(), DATETIME.getSeconds()) 20 } 21 22 getDate(): string { 23 const DATETIME = new Date(); 24 return this.concatDate(DATETIME.getFullYear(), DATETIME.getMonth() + 1, DATETIME.getDate()) 25 } 26 27 fill(value: number): string { 28 return (value > 9 ? '' : '0') + value; 29 } 30 31 concatDate(year: number, month: number, date: number): string { 32 return `${year}${month}${date}`; 33 } 34 35 concatTime(hour: number, minute: number, second: number): string { 36 return `${this.fill(hour)}${this.fill(minute)}${this.fill(second)}`; 37 } 38} 39 40export function getShownTimer(ms: number): string { 41 let seconds: number = Math.round(ms / 1000); 42 let sec: number = seconds % 60; 43 let min: number = (seconds - sec) / 60; 44 if (sec < 10) { 45 sec = 0 + sec; 46 } 47 if (min < 10) { 48 min = 0 + min; 49 } 50 return min + ':' + sec; 51} 52 53export function dateTime(t: number): string { 54 let minute: number = Math.floor(t / 60) % 60 55 let m = minute < 10 ? '0' + minute : minute 56 let second: number = t % 60 57 let s = second < 10 ? '0' + second : second 58 return m + ':' + s; 59}