From 2b29d38bf7ee6355463e79fff1c6a90dd7f94c5b Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期二, 12 八月 2025 10:35:39 +0800
Subject: [PATCH] Merge branch 'Dev' of http://101.37.171.70:10101/r/~jhz/STUWMS into Dev
---
utils/getdateTime.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 92 insertions(+), 1 deletions(-)
diff --git a/utils/getdateTime.js b/utils/getdateTime.js
index 4c960f4..1a1fba9 100644
--- a/utils/getdateTime.js
+++ b/utils/getdateTime.js
@@ -34,7 +34,98 @@
}
return str;
}
-
+/**
+ * @param {Object} hour 灏忔椂鐨勬暟鍊�
+ * @param {Object} min 鍒嗛挓鐨勬暟鍊笺��
+ * @param {Object} sec 绉掔殑鏁板�笺��
+ * @param {Object} millisec 姣鐨勬暟鍊笺��
+ * @param {Object} str 锛坹-m-d h:i:s) y:骞� m:鏈� d:鏃� h:鏃� i:鍒� s:绉�
+ */
+function dateTimeSetHoureStr(hour,min,sec,millisec,str){
+ var date = new Date();
+ date.setHours(hour,min,sec,millisec);
+ var year = date.getFullYear(), //骞�
+ month = date.getMonth() + 1, //鏈�
+ day = date.getDate(), //鏃�
+ hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(), //鏃�
+ minute = date.getMinutes() < 10 ? date.getMinutes() : date.getMinutes(), //鍒�
+ second = date.getSeconds() < 10 ? date.getSeconds() : date.getSeconds(); //绉�
+ month >= 1 && month <= 9 ? (month = "0" + month) : "";
+ day >= 0 && day <= 9 ? (day = "0" + day) : "";
+ hour >= 0 && hour <= 9 ? hour : "";
+ minute >= 0 && minute <= 9 ? (minute = "0" + minute) : "";
+ second >= 0 && second <= 9 ? (second = "0" + second) : "";
+ if(str.indexOf('y') != -1){
+ str = str.replace('y', year)
+ }
+ if(str.indexOf('m') != -1){
+ str = str.replace('m', month)
+ }
+ if(str.indexOf('d') != -1){
+ str = str.replace('d', day)
+ }
+ if(str.indexOf('h') != -1){
+ str = str.replace('h', hour)
+ }
+ if(str.indexOf('i') != -1){
+ str = str.replace('i', minute)
+ }
+ if(str.indexOf('s') != -1){
+ str = str.replace('s', second)
+ }
+ return str;
+}
+/** 璁$畻涓よ�呮椂闂村樊浠ュ皬鏃朵负鍗曚綅
+ * @param {Object} beginStr YYYY-MM-DD HH:MM
+ * @param {Object} endStr YYYY-MM-DD HH:MM
+ */
+function calculateHoursDiff(beginStr, endStr) {
+ // 瑙f瀽寮�濮嬫椂闂�
+ const parseDateTime = (dateTimeStr) => {
+ const [datePart, timePart] = dateTimeStr.split(' ');
+ const [yyyy, mm, dd] = datePart.split('-').map(Number);
+ const [hh, min] = timePart.split(':').map(Number);
+ return new Date(yyyy, mm - 1, dd, hh, min);
+ };
+
+ const beginTime = parseDateTime(beginStr);
+ const endTime = parseDateTime(endStr);
+
+ // 璁$畻姣宸紝骞惰浆鎹负灏忔椂锛堜繚鐣�2浣嶅皬鏁帮級
+ const diffMs = endTime - beginTime;
+ const diffHours = (diffMs / (1000 * 60 * 60)).toFixed(2);
+
+ return parseFloat(diffHours)>0?parseFloat(diffHours):0; // 杩斿洖鏁板瓧绫诲瀷锛屽 3.25
+}
+
+/**杩斿洖鏃堕棿鍔犱笂灏忔椂
+ * @param {Object} dateTimeStr YYYY-MM-DD HH:MM
+ * @param {Object} hoursToAdd 灏忔椂
+ */
+function addHoursToDate(dateTimeStr, hoursToAdd) {
+ // 瑙f瀽杈撳叆鏃ユ湡鏃堕棿
+ const [datePart, timePart] = dateTimeStr.split(' ');
+ const [yyyy, mm, dd] = datePart.split('-').map(Number);
+ const [hh, min] = timePart.split(':').map(Number);
+
+ // 鍒涘缓Date瀵硅薄
+ const date = new Date(yyyy, mm - 1, dd, hh, min);
+
+ // 娣诲姞鎸囧畾灏忔椂鏁帮紙鏀寔灏忔暟灏忔椂锛�
+ date.setTime(date.getTime() + hoursToAdd * 60 * 60 * 1000);
+
+ // 鏍煎紡鍖栦负YYYY-MM-DD HH:MM
+ const newYYYY = String(date.getFullYear()).padStart(4, '0');
+ const newMM = String(date.getMonth() + 1).padStart(2, '0');
+ const newDD = String(date.getDate()).padStart(2, '0');
+ const newHH = String(date.getHours()).padStart(2, '0');
+ const newMin = String(date.getMinutes()).padStart(2, '0');
+
+ return `${newYYYY}-${newMM}-${newDD} ${newHH}:${newMin}`;
+}
module.exports = {
dateTimeStr: dateTimeStr,
+ dateTimeSetHoureStr:dateTimeSetHoureStr,
+ calculateHoursDiff:calculateHoursDiff,
+ addHoursToDate:addHoursToDate,
}
\ No newline at end of file
--
Gitblit v1.9.1