From 509af0f15440944494f1cca3cc4ff65f240c9077 Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Mon, 24 Mar 2025 11:27:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=BF=E6=8D=A2getCurrentHourTime?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E4=B8=BAdayTs=E5=BA=93=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=A0=BC=E5=BC=8F=E5=8C=96=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/common/utils/tools.ts | 64 ++++++++++++------------ entry/src/main/ets/pages/Judge.ets | 10 ++-- entry/src/main/ets/pages/UserInfo.ets | 4 +- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/entry/src/main/ets/common/utils/tools.ts b/entry/src/main/ets/common/utils/tools.ts index 525dab9e..642a4a16 100644 --- a/entry/src/main/ets/common/utils/tools.ts +++ b/entry/src/main/ets/common/utils/tools.ts @@ -134,40 +134,40 @@ export async function getCurrentTime(type?: timeType): Promise { } //获取时分秒毫秒 -export async function getCurrentHourTime(): Promise { - - const date = await systemTime.getDate(); - const year = date.getFullYear(); - let month = date.getMonth() + 1; - let h = date.getHours(); - h = h < 10 ? '0' + h : h; - let m = date.getMinutes(); - m = m < 10 ? '0' + m : m; - let s = date.getSeconds(); - s = s < 10 ? '0' + s : s; - let ss = date.getMilliseconds(); - let nowSS = '' - if (ss < 10) { - nowSS = '00' + ss - } - if (ss >= 10 && ss < 100) { - nowSS = '0' + s - } - return `${h}${m}${s}${nowSS || ss}` -} +// export async function getCurrentHourTime(): Promise { +// +// const date = await systemTime.getDate(); +// const year = date.getFullYear(); +// let month = date.getMonth() + 1; +// let h = date.getHours(); +// h = h < 10 ? '0' + h : h; +// let m = date.getMinutes(); +// m = m < 10 ? '0' + m : m; +// let s = date.getSeconds(); +// s = s < 10 ? '0' + s : s; +// let ss = date.getMilliseconds(); +// let nowSS = '' +// if (ss < 10) { +// nowSS = '00' + ss +// } +// if (ss >= 10 && ss < 100) { +// nowSS = '0' + s +// } +// return `${h}${m}${s}${nowSS || ss}` +// } //时间戳转日期 -export function formatTime(time: number): string { - const h = parseInt(time / 3600) - const minute = parseInt(time / 60 % 60) - const second = Math.ceil(time % 60) - - const hours = h < 10 ? '0' + h : h - const formatSecond = second > 59 ? 59 : second - return `${hours > 0 ? `${hours}:` : `${hours}:`}${minute < 10 ? '0' + minute : minute}:${formatSecond < 10 ? - '0' + formatSecond : formatSecond}` - -} +// export function formatTime(time: number): string { +// const h = parseInt(time / 3600) +// const minute = parseInt(time / 60 % 60) +// const second = Math.ceil(time % 60) +// +// const hours = h < 10 ? '0' + h : h +// const formatSecond = second > 59 ? 59 : second +// return `${hours > 0 ? `${hours}:` : `${hours}:`}${minute < 10 ? '0' + minute : minute}:${formatSecond < 10 ? +// '0' + formatSecond : formatSecond}` +// +// } // 根据指定个数分割数组 diff --git a/entry/src/main/ets/pages/Judge.ets b/entry/src/main/ets/pages/Judge.ets index e4675c5a..2b00229d 100644 --- a/entry/src/main/ets/pages/Judge.ets +++ b/entry/src/main/ets/pages/Judge.ets @@ -46,6 +46,7 @@ import { User } from '../model'; import { GetSyncData } from '../utils/table/Operation'; +import dayTs from '../utils/Date'; @Entry @Component @@ -162,8 +163,8 @@ struct Index { this.singlePlay = AppStorage.get('singlePlay') this.startTime = time.split(' ')[1] this.startFullTime = await getCurrentTime(1); - this.startHourTime = await getCurrentHourTime() - + // this.startHourTime = await getCurrentHourTime() + this.startTime = dayTs().format("HHmmssSSS") this.startExamTime = time setInterval(async () => { @@ -708,10 +709,11 @@ struct Index { Row() { Text('考试用时:').fontColor('#E5CCA1').fontSize(this.FONTSIZE) - Text(formatTime(this.examTime)).fontColor('#FFF').fontSize(this.FONTSIZE) + // Text(formatTime(this.examTime)).fontColor('#FFF').fontSize(this.FONTSIZE) + Text(dayTs(this.examTime).format("YYYY-MM-DD HH:mm:ss")).fontColor('#FFF').fontSize(this.FONTSIZE) }.margin({ bottom: 10 }) - if (this.examSubject == 3) { + if (this.examSubject == "3") { Row() { if (this.judgeConfigObj['375'] == '0') { Text(`应行驶:${this.examMileage}m`) diff --git a/entry/src/main/ets/pages/UserInfo.ets b/entry/src/main/ets/pages/UserInfo.ets index cf4e4c1a..8ac5f893 100644 --- a/entry/src/main/ets/pages/UserInfo.ets +++ b/entry/src/main/ets/pages/UserInfo.ets @@ -40,6 +40,7 @@ import { import { BusinessError } from '@ohos.base'; import { GetSyncData } from '../utils/table/Operation'; import { GetCurrentUserKeyValue } from './UserInfo/utils'; +import dayTs from '../utils/Date'; @Entry @Component @@ -1004,7 +1005,8 @@ struct UserInfo { async beginExam(): Promise { // const { examSubject, plateNo } = this.carInfo; const date = new Date() - const startHourTime = await getCurrentHourTime() + // const startHourTime = await getCurrentHourTime() + const startHourTime = dayTs().format("HHmmssSSS") AppStorage.setOrCreate('startHourTime', startHourTime) const photoBase64 = await this.getPhoto(); if (photoBase64 == '') {