util.js 837 B

1234567891011121314151617181920212223242526272829303132
  1. const formatTime = 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 [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  9. }
  10. const formatTime2 = date => {
  11. const year = date.getFullYear()
  12. const month = date.getMonth() + 1
  13. const day = date.getDate()
  14. const hour = date.getHours()
  15. const minute = date.getMinutes()
  16. const second = date.getSeconds()
  17. return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  18. }
  19. const formatNumber = n => {
  20. n = n.toString()
  21. return n[1] ? n : '0' + n
  22. }
  23. module.exports = {
  24. formatTime: formatTime,
  25. formatTime2
  26. }