fix: 替换getCurrentHourTime函数为dayTs库的时间格式化,优化时间处理逻辑
This commit is contained in:
parent
6e1c80cb04
commit
509af0f154
@ -134,40 +134,40 @@ export async function getCurrentTime(type?: timeType): Promise<string> {
|
||||
}
|
||||
|
||||
//获取时分秒毫秒
|
||||
export async function getCurrentHourTime(): Promise<string> {
|
||||
|
||||
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<string> {
|
||||
//
|
||||
// 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}`
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
// 根据指定个数分割数组
|
||||
|
||||
@ -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`)
|
||||
|
||||
@ -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<BeginExamRequest> {
|
||||
// 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 == '') {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user