MCPcopy
hub / github.com/pythonstock/stock / formatTime

Function formatTime

frontend/src/utils/index.js:59–95  ·  view source on GitHub ↗
(time, option)

Source from the content-addressed store, hash-verified

57 * @returns {string}
58 */
59export function formatTime(time, option) {
60 if (('' + time).length === 10) {
61 time = parseInt(time) * 1000
62 } else {
63 time = +time
64 }
65 const d = new Date(time)
66 const now = Date.now()
67
68 const diff = (now - d) / 1000
69
70 if (diff < 30) {
71 return '刚刚'
72 } else if (diff < 3600) {
73 // less 1 hour
74 return Math.ceil(diff / 60) + '分钟前'
75 } else if (diff < 3600 * 24) {
76 return Math.ceil(diff / 3600) + '小时前'
77 } else if (diff < 3600 * 24 * 2) {
78 return '1天前'
79 }
80 if (option) {
81 return parseTime(time, option)
82 } else {
83 return (
84 d.getMonth() +
85 1 +
86 '月' +
87 d.getDate() +
88 '日' +
89 d.getHours() +
90 '时' +
91 d.getMinutes() +
92 '分'
93 )
94 }
95}
96
97/**
98 * @param {string} url

Callers 1

formatTime.spec.jsFile · 0.90

Calls 1

parseTimeFunction · 0.85

Tested by

no test coverage detected