util.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 formatNumber = n => {
  11. n = n.toString()
  12. return n[1] ? n : '0' + n
  13. }
  14. const formatSeconds = theTime => {
  15. let theTime1 = 0
  16. let theTime2 = 0
  17. if (theTime > 60) {
  18. theTime1 = parseInt(theTime / 60)
  19. theTime = parseInt(theTime % 60)
  20. if (theTime1 > 60) {
  21. theTime2 = parseInt(theTime1 / 60)
  22. theTime1 = parseInt(theTime1 % 60)
  23. }
  24. }
  25. let result = '' + parseInt(theTime) + '秒'
  26. if (theTime1 > 0) {
  27. result = '' + parseInt(theTime1) + '分' + result
  28. }
  29. if (theTime2 > 0) {
  30. result = '' + parseInt(theTime2) + '小时' + result
  31. }
  32. return result
  33. }
  34. const getMultResult = select=>{
  35. let prevList = ["", "A","B","C", "D", "E","F"]
  36. let slist = ''+select
  37. let res = ""
  38. for( let i in slist){
  39. res+=prevList[slist[i]]
  40. console.log(slist[i], prevList[slist[i]] )
  41. }
  42. return res
  43. }
  44. module.exports = {
  45. formatSeconds: formatSeconds,
  46. formatTime: formatTime,
  47. getMultResult
  48. }