tool.wxs 1.0 KB

123456789101112131415161718192021222324252627282930
  1. //日期格式化-------------------------------------------------------------
  2. var formatTime = function (strDate) {
  3. return 1
  4. // 解决ios出现NaN问题
  5. var realDate = strDate ? getDate(strDate.replace(getRegExp('-', 'g'), '/')) : getDate();
  6. var regYear = getRegExp("(y+)", "i");
  7. var date = [
  8. ["M+", realDate.getMonth() + 1],
  9. ["d+", realDate.getDate()],
  10. ["h+", realDate.getHours()],
  11. ["m+", realDate.getMinutes()],
  12. ["s+", realDate.getSeconds()],
  13. ["q+", Math.floor((realDate.getMonth() + 3) / 3)],
  14. ["S+", realDate.getMilliseconds()],
  15. ];
  16. var reg1 = regYear.exec(format);
  17. if (reg1) {
  18. format = format.replace(reg1[1], (realDate.getFullYear() + '').substring(4 - reg1[1].length));
  19. }
  20. for (var i = 0; i < date.length; i++) {
  21. var reg2 = getRegExp("(" + date[i][0] + ")").exec(format);
  22. if (reg2) {
  23. format = format.replace(reg2[1], reg2[1].length == 1 ? v : ("00" + date[i][1]).substring(("" + date[i][1]).length));
  24. }
  25. }
  26. return format;
  27. }
  28. module.exports = {
  29. formatTime: formatTime//日期格式化
  30. }