时间格式转换为Json的时间格式
function convertDateToJsonDate(strDate) {
var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
function(a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');
var t1 = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
return "\/Date(" + t1 + ")\/";
}
json 的时间格式转换为字符串时间格式
if (time != null && time != "" && typeof (time) != 'undefined') {
if (time.toString().indexOf('/Date') >= 0) {
var date = new Date(parseInt(time.replace("/Date(", "").replace(")/", ""), 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var h = date.getUTCHours();
var m = date.getUTCMinutes();
var s = date.getUTCSeconds();
var longDate = date.getFullYear() + "-" + month + "-" + currentDate + " " + h + ":" + m + ":" + s;
return longDate;
}
}
return "";
}
测试代码:
function ss() {
var m = convertDateToJsonDate("2012-12-10 12:25:30");
var s = ChangeDateFormat(m);
alert(s);
}