util.js 665 B

123456789101112131415161718192021222324252627
  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 formatMonth = date => {
  11. const year = date.getFullYear()
  12. const month = date.getMonth() + 1
  13. return [year, month].map(formatNumber).join('-')
  14. }
  15. const formatNumber = n => {
  16. n = n.toString()
  17. return n[1] ? n : '0' + n
  18. }
  19. module.exports = {
  20. formatTime: formatTime,
  21. formatMonth: formatMonth
  22. }