util.js 681 B

123456789101112131415161718192021222324
  1. "use strict";
  2. function formatTime(time, format = "yyyy年MM月dd日") {
  3. const date = new Date(time);
  4. const formatObj = {
  5. "y+": date.getFullYear(),
  6. "M+": date.getMonth() + 1,
  7. "d+": date.getDate(),
  8. "H+": date.getHours(),
  9. "m+": date.getMinutes(),
  10. "s+": date.getSeconds()
  11. };
  12. for (let key in formatObj) {
  13. if (new RegExp(`(${key})`).test(format)) {
  14. const str = formatObj[key].toString();
  15. format = format.replace(
  16. RegExp.$1,
  17. RegExp.$1.length === 1 ? str : ("00" + str).slice(str.length)
  18. );
  19. }
  20. }
  21. return format;
  22. }
  23. exports.formatTime = formatTime;
  24. //# sourceMappingURL=../../.sourcemap/mp-weixin/utils/util.js.map