zoukankan      html  css  js  c++  java
  • 时间格式化代码

    格式化时间函数:

     1 function dateFormat(date, format) {
     2     if (typeof date === "string") {
     3         var mts = date.match(/(\/Date\((\d+)\)\/)/);
     4         if (mts && mts.length >= 3) {
     5             date = parseInt(mts[2]);
     6         }
     7     }
     8     date = new Date(date);
     9     if (!date || date.toUTCString() == "Invalid Date") {
    10         return "";
    11     }
    12     var map = {
    13         "M": date.getMonth() + 1, //月份 
    14         "d": date.getDate(), //
    15         "h": date.getHours(), //小时 
    16         "m": date.getMinutes(), //
    17         "s": date.getSeconds(), //
    18         "q": Math.floor((date.getMonth() + 3) / 3), //季度 
    19         "S": date.getMilliseconds() //毫秒 
    20     };
    21     format = format.replace(/([yMdhmsqS])+/g, function(all, t) {
    22         var v = map[t];
    23         if (v !== undefined) {
    24             if (all.length > 1) {
    25                 v = '0' + v;
    26                 v = v.substr(v.length - 2);
    27             }
    28             return v;
    29         } else if (t === 'y') {
    30             return (date.getFullYear() + '').substr(4 - all.length);
    31         }
    32         return all;
    33     });
    34     return format;
    35 }
    36 return dateFormat(value, arg);
  • 相关阅读:
    Js
    CSS
    CSS
    第七周作业及总结
    第六周作业及总结
    第五周作业及总结
    第四周作业及总结
    第三周作业及总结
    7-1 判断上三角矩阵
    第二周作业及总结
  • 原文地址:https://www.cnblogs.com/seeding/p/15222125.html
Copyright © 2011-2022 走看看