util.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 formatDate = date => {
  11. const year = date.getFullYear()
  12. const month = date.getMonth() + 1
  13. const day = date.getDate()
  14. return `${[year, month, day].map(formatNumber).join('-')} `
  15. }
  16. const formatNumber = n => {
  17. n = n.toString()
  18. return n[1] ? n : `0${n}`
  19. }
  20. const simleInfo = msg => {
  21. wx.showModal({
  22. title: '提示',
  23. content: msg,
  24. showCancel: false,
  25. success(res) {
  26. }
  27. })
  28. }
  29. const simleInfoWithBack = msg => {
  30. wx.showModal({
  31. title: '提示',
  32. content: msg,
  33. showCancel: false,
  34. success(res) {
  35. wx.navigateBack({})
  36. }
  37. })
  38. }
  39. module.exports = {
  40. simleInfo: simleInfo,
  41. simleInfoWithBack: simleInfoWithBack,
  42. formatNumber: formatNumber,
  43. formatTime: formatTime,
  44. formatDate: formatDate,
  45. }