|
@@ -6,7 +6,7 @@
|
6
|
6
|
* Parse the time to string
|
7
|
7
|
* @param {(Object|string|number)} time
|
8
|
8
|
* @param {string} cFormat
|
9
|
|
- * @returns {string}
|
|
9
|
+ * @returns {string | null}
|
10
|
10
|
*/
|
11
|
11
|
export function parseTime(time, cFormat) {
|
12
|
12
|
if (arguments.length === 0) {
|
|
@@ -34,14 +34,11 @@ export function parseTime(time, cFormat) {
|
34
|
34
|
s: date.getSeconds(),
|
35
|
35
|
a: date.getDay()
|
36
|
36
|
}
|
37
|
|
- const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
|
38
|
|
- let value = formatObj[key]
|
|
37
|
+ const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
|
|
38
|
+ const value = formatObj[key]
|
39
|
39
|
// Note: getDay() returns 0 on Sunday
|
40
|
40
|
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
|
41
|
|
- if (result.length > 0 && value < 10) {
|
42
|
|
- value = '0' + value
|
43
|
|
- }
|
44
|
|
- return value || 0
|
|
41
|
+ return value.toString().padStart(2, '0')
|
45
|
42
|
})
|
46
|
43
|
return time_str
|
47
|
44
|
}
|