/date()/转换成常见的时间格式

127 阅读1分钟

搜集到两种方法:

从C#的Datatime格式通过Json传到Js里面,时间会显示成时间戳/Date(1354116249000)/ ,js转化如下

function GetDateFormat(str) {
return new Date(parseInt(str.substr(6, 13))).toLocaleDateString();
}

GetDateFormat(’/Date(1354116249000)/ ‘)—> 2017/1/1

原文:blog.csdn.net/luckzhang_l…

/date()/转换成常见的时间格式

function FormatToDate(val) {
    if (val != null) {
        var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
        //月份为0-11,所以+1,月份小于10时补个0
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        return date.getFullYear() + "-" + month + "-" + currentDate;
    }
    return "";
}

原文:blog.csdn.net/xiaouncle/a…

欢迎进qq群交流:704028989