From 1b419ccf217dbcace15987f1c0fe26b9e15d1d4b Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期三, 16 十月 2024 10:26:56 +0800 Subject: [PATCH] 工艺绑定优化 --- src/utils/dateUtil.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-) diff --git a/src/utils/dateUtil.ts b/src/utils/dateUtil.ts index e18387d..20c81c1 100644 --- a/src/utils/dateUtil.ts +++ b/src/utils/dateUtil.ts @@ -1,3 +1,11 @@ +/* + * @Description: file content + * @Author: Ben Lin + * @version: + * @Date: 2024-06-18 15:09:47 + * @LastEditors: Ben Lin + * @LastEditTime: 2024-07-04 20:04:14 + */ /** * Independent time operation tool to facilitate subsequent switch to dayjs */ @@ -14,4 +22,32 @@ return dayjs(date).format(format); } +export function intToTime(intValue: number): string { + const hours = Math.floor(intValue / 100); + const minutes = intValue % 100; + return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`; +} + +export function tsToHHmm(ts) { + var date = new Date(ts); + var hours = date.getHours().toString().padStart(2, '0'); + var minutes = date.getMinutes().toString().padStart(2, '0'); + return hours + minutes; +} + +export function formatTime(date: Date) { + const hours = date.getHours().toString().padStart(2, '0'); + const minutes = date.getMinutes().toString().padStart(2, '0'); + return `${hours}:${minutes}`; +} + +export function convertTimeToDate(time: string) { + // 鍋囪鏃堕棿鏄綋澶╃殑鏃堕棿锛屾墍浠ユ垜浠渶瑕佹瀯閫犱竴涓寘鍚粖澶╂棩鏈熷拰鎻愪緵鐨勬椂闂寸殑瀛楃涓� + const today = new Date(); + const [hours, minutes] = time.split(':').map(Number); + // 璁剧疆鏃堕棿锛屼繚鐣欎粖澶╃殑鏃ユ湡骞惰缃寚瀹氱殑灏忔椂鍜屽垎閽� + today.setHours(hours, minutes, 0, 0); + return dayjs(today); +} + export const dateUtil = dayjs; -- Gitblit v1.9.3