index.js 529 B

123456789101112131415161718192021222324
  1. function formatNumber (n) {
  2. const str = n.toString()
  3. return str[1] ? str : `0${str}`
  4. }
  5. export function formatTime (date) {
  6. const year = date.getFullYear()
  7. const month = date.getMonth() + 1
  8. const day = date.getDate()
  9. const hour = date.getHours()
  10. const minute = date.getMinutes()
  11. const second = date.getSeconds()
  12. const t1 = [year, month, day].map(formatNumber).join('/')
  13. const t2 = [hour, minute, second].map(formatNumber).join(':')
  14. return `${t1} ${t2}`
  15. }
  16. export default {
  17. formatNumber,
  18. formatTime
  19. }