-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdateformat.js
82 lines (76 loc) · 2.49 KB
/
dateformat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function dateformat (format, date = new Date()) {
// yyyy-MM-dd hh:mm:ss
if (!(date instanceof Date)) throw new TypeError('date must be a Date')
const timeObj = {
yyyy: date.getFullYear(),
MM: date.getMonth() + 1,
dd: date.getDate(),
hh: date.getHours(),
mm: date.getMinutes(),
ss: date.getSeconds(),
SSS: date.getMilliseconds()
}
const padOptions = {
MM: 2,
dd: 2,
hh: 2,
mm: 2,
ss: 2,
SSS: 3
}
Object.keys(timeObj).forEach(key => {
const option = padOptions[key]
if (option) {
timeObj[key] = String(timeObj[key]).padStart(option, '0')
}
})
return format.replace()
}
dateformat()
// format(formatStr) {
// if (!this.isValid()) return C.INVALID_DATE_STRING
// const str = formatStr || C.FORMAT_DEFAULT
// const zoneStr = Utils.z(this)
// const locale = this.$locale()
// const { $H, $m, $M } = this
// const {
// weekdays, months, meridiem
// } = locale
// const getShort = (arr, index, full, length) => (
// (arr && (arr[index] || arr(this, str))) || full[index].substr(0, length)
// )
// const get$H = num => (
// Utils.s($H % 12 || 12, num, '0')
// )
// const meridiemFunc = meridiem || ((hour, minute, isLowercase) => {
// const m = (hour < 12 ? 'AM' : 'PM')
// return isLowercase ? m.toLowerCase() : m
// })
// const matches = {
// YY: String(this.$y).slice(-2),
// YYYY: this.$y,
// M: $M + 1,
// MM: Utils.s($M + 1, 2, '0'),
// MMM: getShort(locale.monthsShort, $M, months, 3),
// MMMM: getShort(months, $M),
// D: this.$D,
// DD: Utils.s(this.$D, 2, '0'),
// d: String(this.$W),
// dd: getShort(locale.weekdaysMin, this.$W, weekdays, 2),
// ddd: getShort(locale.weekdaysShort, this.$W, weekdays, 3),
// dddd: weekdays[this.$W],
// H: String($H),
// HH: Utils.s($H, 2, '0'),
// h: get$H(1),
// hh: get$H(2),
// a: meridiemFunc($H, $m, true),
// A: meridiemFunc($H, $m, false),
// m: String($m),
// mm: Utils.s($m, 2, '0'),
// s: String(this.$s),
// ss: Utils.s(this.$s, 2, '0'),
// SSS: Utils.s(this.$ms, 3, '0'),
// Z: zoneStr // 'ZZ' logic below
// }
// return str.replace(C.REGEX_FORMAT, (match, $1) => $1 || matches[match] || zoneStr.replace(':', '')) // 'ZZ'
// }