zoukankan      html  css  js  c++  java
  • 时间字符串格式化 js

    /*格式化*/

    function dateFormat(dateString, format) {
    if (!dateString) return "";
    //var time = new Date(dateString.replace(/-/g, '/').replace(/T|Z/g, ' ').trim());
    var time = getDate(dateString);
    var o = {
    "M+": time.getMonth() + 1, //月份
    "d+": time.getDate(), //日
    "h+": time.getHours(), //小时
    "m+": time.getMinutes(), //分
    "s+": time.getSeconds(), //秒
    "q+": Math.floor((time.getMonth() + 3) / 3), //季度
    "S": time.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (time.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return format;
    }

    /*对象化*/
    function getDate(strDate) {
    var date = eval('new Date(' + strDate.replace(/d+(?=-[^-]+$)/,
    function (a) { return parseInt(a, 10) - 1; }).match(/d+/g) + ')');
    return date;
    }

  • 相关阅读:
    EFCore实践教程三
    EFCore实践测试二
    EFCore实践测试一
    git学习3
    git学习2
    git学习1
    ABP学习
    autofac笔记
    时间计算本质理论3-平行宇宙,对未来的子线程计算
    时间计算本质理论2-时间计算速度的不同步
  • 原文地址:https://www.cnblogs.com/ws-zpp/p/6755685.html
Copyright © 2011-2022 走看看