util.ts 474 B

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