储能智慧云小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Background_base64 = path => {
  15. return 'data:image/png;base64,' + wx.getFileSystemManager().readFileSync(path, 'base64');
  16. }
  17. const getdataTime = n => {
  18. // 引入moment.js库
  19. const moment = require('moment');
  20. // 获取当前时间
  21. let currentTime = moment();
  22. if (n==7) {
  23. // 获取7天前的时间
  24. let sevenDaysAgo = moment().subtract(7, 'days');
  25. // return sevenDaysAgo.format('YYYY-MM-DD HH:mm:ss');
  26. return sevenDaysAgo.format('YYYY-MM');
  27. }else if (n==31) {
  28. // 获取30天前的时间
  29. let thirtyDaysAgo = moment().subtract(30, 'days');
  30. return thirtyDaysAgo.format('YYYY-MM');
  31. }else if (n==365){
  32. // 获取当前年份的开始时间
  33. let startOfYear = moment().subtract(1, 'days');
  34. return startOfYear.format('YYYY');
  35. }else if(n=='当日'){
  36. // 格式化当前时间为 YYYY-MM-DD
  37. return currentTime.format('YYYY-MM-DD');
  38. }
  39. }
  40. const CumulativeTime = n => {
  41. // 引入moment.js库
  42. const moment = require('moment');
  43. // 获取7天前的时间
  44. let sevenDaysAgo = moment().subtract(n, 'days');
  45. // return sevenDaysAgo.format('YYYY-MM-DD HH:mm:ss');
  46. return sevenDaysAgo.format('YYYY-MM-DD');
  47. }
  48. // 获取当前时间
  49. const CumulativeTimess = n => {
  50. // 引入moment.js库
  51. const moment = require('moment');
  52. // 获取7天前的时间
  53. let sevenDaysAgo = moment().subtract(n, 'days');
  54. return sevenDaysAgo.format('YYYY-MM-DD HH:mm:ss');
  55. }
  56. // 时间戳转时间
  57. const timestamp = n => {
  58. // 使用 Date 对象将时间戳转换为日期时间字符串
  59. const date = new Date(n);
  60. // 使用 Date 对象的方法获取年月日时分秒
  61. const year = date.getFullYear();
  62. const month = date.getMonth() + 1; // 月份是从0开始的,需要加1
  63. const day = date.getDate();
  64. const hours = date.getHours();
  65. const minutes = date.getMinutes();
  66. const seconds = date.getSeconds();
  67. // 构造你需要的日期时间格式
  68. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  69. }
  70. module.exports = {
  71. formatTime,
  72. Background_base64,
  73. getdataTime,
  74. CumulativeTime,
  75. timestamp,
  76. CumulativeTimess
  77. }