getDate.js 536 B

123456789101112131415161718192021
  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. return [hour, minute, second].map(formatNumber).join(':')
  10. }
  11. const formatNumber = n => {
  12. n = n.toString()
  13. return n[1] ? n : '0' + n
  14. }
  15. module.exports = {
  16. formatTime: formatTime
  17. }