文章出處

起因

對于從C#返回的日期字段,當進行JSON序列化后,在前臺JS里顯示的并不是真正的日期,這讓我們感覺很不爽,我們不可能為了這東西,把所有日期字段都變成string吧,所以,找了一個JS的擴展方法,來實現這個功能

實現

function ChangeDateFormat(jsondate) {
    jsondate = jsondate.replace("/Date(", "").replace(")/", "");
    if (jsondate.indexOf("+") > 0) {
        jsondate = jsondate.substring(0, jsondate.indexOf("+"));
    }
    else if (jsondate.indexOf("-") > 0) {
        jsondate = jsondate.substring(0, jsondate.indexOf("-"));
    }

    var date = new Date(parseInt(jsondate, 10));
    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
        + "日"
        + " "
        + date.getHours()
        + ":"
        + date.getMinutes();
}
//調用:ChangeDateFormat(data[i].arrDate)

調用

  $.ajax({
            type: "Get",
            textType: "json",
            url: "/UserInfo/GetUserWithdraw",
            data: { id: id },
            success: function (data) {
                var result = html.replace(reg, function (node, key) {
                    return {
                        'Money': data.Money,
                        'AddTime': ChangeDateFormat(data.AddTime),
                        'CashTime': data.CashTime
                    }[key];
                });

                TsingdaTips.ask({ msg: result, show_btn: false, title: "提現申請詳情" });//預計打款時間等于申請時音后的(5號或20號)
            }
        });

 

 

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()