light-h5-core-lib 2.11.0 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/util/DateUtil.js +47 -5
- package/package.json +1 -1
- package/type/index.d.ts +13 -0
package/common/util/DateUtil.js
CHANGED
|
@@ -34,11 +34,19 @@ class DateUtil {
|
|
|
34
34
|
}
|
|
35
35
|
const m = Math.floor((s - h * 3600) / 60);
|
|
36
36
|
s = s - h * 3600 - m * 60;
|
|
37
|
-
let result = isSingle0
|
|
37
|
+
let result = isSingle0
|
|
38
|
+
? h < 10
|
|
39
|
+
? `0${h}`
|
|
40
|
+
: h.toString()
|
|
41
|
+
: h.toString();
|
|
38
42
|
result += separator;
|
|
39
|
-
result =
|
|
43
|
+
result =
|
|
44
|
+
result +
|
|
45
|
+
(isSingle0 ? (m < 10 ? `0${m}` : m.toString()) : m.toString());
|
|
40
46
|
result += separator;
|
|
41
|
-
result =
|
|
47
|
+
result =
|
|
48
|
+
result +
|
|
49
|
+
(isSingle0 ? (s < 10 ? `0${s}` : s.toString()) : s.toString());
|
|
42
50
|
return result;
|
|
43
51
|
}
|
|
44
52
|
/**
|
|
@@ -50,11 +58,45 @@ class DateUtil {
|
|
|
50
58
|
static format_MS(s, separator = ":", isSingle0 = true) {
|
|
51
59
|
const m = Math.floor(s / 60);
|
|
52
60
|
s = s - m * 60;
|
|
53
|
-
let result = isSingle0
|
|
61
|
+
let result = isSingle0
|
|
62
|
+
? m < 10
|
|
63
|
+
? `0${m}`
|
|
64
|
+
: m.toString()
|
|
65
|
+
: m.toString();
|
|
54
66
|
result += separator;
|
|
55
|
-
result =
|
|
67
|
+
result =
|
|
68
|
+
result +
|
|
69
|
+
(isSingle0 ? (s < 10 ? `0${s}` : s.toString()) : s.toString());
|
|
56
70
|
return result;
|
|
57
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* 秒级时间戳转日期字符串
|
|
74
|
+
* @param seconds 秒级时间戳
|
|
75
|
+
* @param separator 分隔符,默认 "/"
|
|
76
|
+
* @returns 如 "2026/2/1"
|
|
77
|
+
*/
|
|
78
|
+
static formatDate(seconds, separator = "/") {
|
|
79
|
+
const date = new Date(seconds * 1000);
|
|
80
|
+
const year = date.getFullYear();
|
|
81
|
+
const month = date.getMonth() + 1;
|
|
82
|
+
const day = date.getDate();
|
|
83
|
+
return `${year}${separator}${month}${separator}${day}`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 秒级时间戳转日期时间字符串
|
|
87
|
+
* @param seconds 秒级时间戳
|
|
88
|
+
* @returns 如 "2026/2/1 14:30:00"
|
|
89
|
+
*/
|
|
90
|
+
static formatDateTime(seconds) {
|
|
91
|
+
const date = new Date(seconds * 1000);
|
|
92
|
+
const y = date.getFullYear();
|
|
93
|
+
const m = date.getMonth() + 1;
|
|
94
|
+
const d = date.getDate();
|
|
95
|
+
const h = date.getHours().toString().padStart(2, "0");
|
|
96
|
+
const min = date.getMinutes().toString().padStart(2, "0");
|
|
97
|
+
const s = date.getSeconds().toString().padStart(2, "0");
|
|
98
|
+
return `${y}/${m}/${d} ${h}:${min}:${s}`;
|
|
99
|
+
}
|
|
58
100
|
/**
|
|
59
101
|
* 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计<b style="color:red">当天时间24:00</b>
|
|
60
102
|
* @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
|
package/package.json
CHANGED
package/type/index.d.ts
CHANGED
|
@@ -159,6 +159,19 @@ export declare class DateUtil {
|
|
|
159
159
|
* @param isSingle0 是否补0(default:true)
|
|
160
160
|
*/
|
|
161
161
|
static format_MS(s: number, separator?: string, isSingle0?: boolean): string;
|
|
162
|
+
/**
|
|
163
|
+
* 秒级时间戳转日期字符串
|
|
164
|
+
* @param seconds 秒级时间戳
|
|
165
|
+
* @param separator 分隔符,默认 "/"
|
|
166
|
+
* @returns 如 "2026/2/1"
|
|
167
|
+
*/
|
|
168
|
+
static formatDate(seconds: number, separator?: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* 秒级时间戳转日期时间字符串
|
|
171
|
+
* @param seconds 秒级时间戳
|
|
172
|
+
* @returns 如 "2026/2/1 14:30:00"
|
|
173
|
+
*/
|
|
174
|
+
static formatDateTime(seconds: number): string;
|
|
162
175
|
/**
|
|
163
176
|
* 获取下一天的时间(凌晨)秒 存在1ms误差可以忽略不计<b style="color:red">当天时间24:00</b>
|
|
164
177
|
* @param nowSecond 现在的时间秒 ( 服务器的时间(一般))
|