odc.xiaohui
2023-04-07 f693c859cdaf607c2a146ef89a7a2ce0d9476d1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export const formatTime = (date: Date) => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
 
  return (
    [year, month, day].map(formatNumber).join('/') +
    ' ' +
    [hour, minute, second].map(formatNumber).join(':')
  )
}
 
const formatNumber = (n: number) => {
  const s = n.toString()
  return s[1] ? s : '0' + s
}