MCPcopy
hub / github.com/PanJiaChen/electron-vue-admin / parseTime

Function parseTime

src/renderer/utils/index.js:5–35  ·  view source on GitHub ↗
(time, cFormat)

Source from the content-addressed store, hash-verified

3 */
4
5export function parseTime(time, cFormat) {
6 if (arguments.length === 0) {
7 return null
8 }
9 const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
10 let date
11 if (typeof time === 'object') {
12 date = time
13 } else {
14 if (('' + time).length === 10) time = parseInt(time) * 1000
15 date = new Date(time)
16 }
17 const formatObj = {
18 y: date.getFullYear(),
19 m: date.getMonth() + 1,
20 d: date.getDate(),
21 h: date.getHours(),
22 i: date.getMinutes(),
23 s: date.getSeconds(),
24 a: date.getDay()
25 }
26 const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
27 let value = formatObj[key]
28 if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
29 if (result.length > 0 && value < 10) {
30 value = '0' + value
31 }
32 return value || 0
33 })
34 return time_str
35}
36
37export function formatTime(time, option) {
38 time = +time * 1000

Callers 1

formatTimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected