• js处理日期


    /Date(-62135596800000)/ 如何用js转化为日期时间格式 2015-11-20 14:33:20像这样

    var a = '/Date(-62135596800000)/'

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

    使用方法:new Date(parseInt(a.slice(6))).format("yyyy-MM-dd")


    /**
    * 格式化时间显示方式
    * 用法:format="yyyy-MM-dd hh:mm:ss";
    */
    utils.formatDate = function (v, format) {
    if (!v) return "";
    var d = v;
    if (typeof v === 'string') {
    if (v.indexOf("/Date(") > -1)
    d = new Date(parseInt(v.replace("/Date(", "").replace(")/", ""), 10));
    else
    d = new Date(Date.parse(v.replace(/-/g, "/").replace("T", " ").split(".")[0]));//.split(".")[0] 用来处理出现毫秒的情况,截取掉.xxx,否则会出错
    }
    var o = {
    "M+": d.getMonth() + 1, //month
    "d+": d.getDate(), //day
    "h+": d.getHours(), //hour
    "m+": d.getMinutes(), //minute
    "s+": d.getSeconds(), //second
    "q+": Math.floor((d.getMonth() + 3) / 3), //quarter
    "S": d.getMilliseconds() //millisecond
    };
    if (/(y+)/.test(format)) {
    format = format.replace(RegExp.$1, (d.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;
    };

     
  • 相关阅读:
    模块三
    python的6种基本数据类型--字典
    python的6种基本数据类型--集合
    数据集之集合
    锚点使用
    JSON返回DateTime/Date('123123123')/解决办法
    JSON返回DateTime/Date('123123123')/解决办法
    设计模式-系列索引
    设计模式-系列索引
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/chensong0524/p/8384775.html
Copyright © 2020-2023  润新知