From 4af6cee58386098c18d702eada749562a164f7d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=9D=B0?= Date: Fri, 21 Oct 2022 18:18:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E6=9C=9F=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E4=BC=98=E5=8C=96=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 罗杰 --- entry/src/main/ets/model/DateTimeUtil.ts | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 entry/src/main/ets/model/DateTimeUtil.ts diff --git a/entry/src/main/ets/model/DateTimeUtil.ts b/entry/src/main/ets/model/DateTimeUtil.ts new file mode 100644 index 0000000..77e8ddc --- /dev/null +++ b/entry/src/main/ets/model/DateTimeUtil.ts @@ -0,0 +1,49 @@ +/** + * @file 日期工具 + */ +export default class DateTimeUtil { + + /** + * 时分秒 + */ + getTime() { + const DATETIME = new Date() + return this.concatTime(DATETIME.getHours(), DATETIME.getMinutes(), DATETIME.getSeconds()) + } + + /** + * 年月日 + */ + getDate() { + const DATETIME = new Date() + return this.concatDate(DATETIME.getFullYear(), DATETIME.getMonth() + 1, DATETIME.getDate()) + } + + /** + * 日期不足两位补充0 + * @param value-数据值 + */ + fill(value: number) { + return (value > 9 ? '' : '0') + value + } + + /** + * 年月日格式修饰 + * @param year + * @param month + * @param date + */ + concatDate(year: number, month: number, date: number) { + return `${year}${this.fill(month)}${this.fill(date)}` + } + + /** + * 时分秒格式修饰 + * @param hours + * @param minutes + * @param seconds + */ + concatTime(hours: number, minutes: number, seconds: number) { + return `${this.fill(hours)}${this.fill(minutes)}${this.fill(seconds)}` + } +} \ No newline at end of file -- Gitee