地铁二期项目正式开始

formatdate.js 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. layui.use(['table', 'jquery'], function () {
  2. //时间戳的处理
  3. layui.laytpl.toDateString = function (d, format) {
  4. var date = new Date(d || new Date())
  5. , ymd = [
  6. this.digit(date.getFullYear(), 4)
  7. , this.digit(date.getMonth() + 1)
  8. , this.digit(date.getDate())
  9. ]
  10. , hms = [
  11. this.digit(date.getHours())
  12. , this.digit(date.getMinutes())
  13. , this.digit(date.getSeconds())
  14. ];
  15. format = format || 'yyyy-MM-dd HH:mm:ss';
  16. return format.replace(/yyyy/g, ymd[0])
  17. .replace(/MM/g, ymd[1])
  18. .replace(/dd/g, ymd[2])
  19. .replace(/HH/g, hms[0])
  20. .replace(/mm/g, hms[1])
  21. .replace(/ss/g, hms[2]);
  22. };
  23. //数字前置补零
  24. layui.laytpl.digit = function (num, length, end) {
  25. var str = '';
  26. num = String(num);
  27. length = length || 2;
  28. for (var i = num.length; i < length; i++) {
  29. str += '0';
  30. }
  31. return num < Math.pow(10, length) ? str + (num | 0) : num;
  32. };
  33. });