json时间转换问题
在一般处理程序中,
return "{" +
"id: '" + cevent.id + "'," +
"title: '" + HttpContext.Current.Server.HtmlEncode(cevent.title) + "'," +
"start: " + ConvertToTimestamp(cevent.start).ToString() + "," +
"end: " + ConvertToTimestamp(cevent.end).ToString() + "," +
"warntime: " + ConvertToTimestamp(cevent.warntime).ToString() +","+
"allDay:" + allDay + "," +
"description: '" + HttpContext.Current.Server.HtmlEncode(cevent.description) + "'," +
"warnid: '" + cevent.warnid + "'" +
"},";
start,end,warntime,都为时间,转换正确,在js中,
if (event.warnid == 0) {
document.getElementById("isWarn1").checked = false;
$("#wtime1").css("display", "none");
$("#Text1").val("" + event.start.toLocaleDateString());
$("#Text2").val("" + "08:00:00");
}
else {
document.getElementById("isWarn1").checked = true;
$("#wtime1").css("display", "block");
$("#Text1").val("" + event.warntime.toLocaleDateString());
$("#Text2").val("" + event.warntime.toLocaleTimeString());
}
$("#eventStart").text("" + event.start.toLocaleString());
if (event.end === null) {
$("#eventEnd").text("" + event.start.toLocaleString());
}
else {
$("#eventEnd").text("" + event.end.toLocaleString());
}
start,end都可以正常转换,但是warntime转换却报错,无法识别toLocaleDateString()方法,用var a=new date();
a.setTime(warntime)转换出来的日期不正确,无论怎样都会转换为1970年0月的日期
------解决方案--------------------确认下js的date参数,你都不把返回的json日期格式说出来,谁知道你到底什么错误
顺带说下
2010-10-10这种格式是转化失败的
要转成2010/10/10这种格式