发布网友
共2个回答
懂视网
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; }
热心网友
通过json获取的时间对象和javascript通过new Date()创造的对象是有区别的的,json的时间对象如下所示:
var d = {"date":20,"day":2,"hours":2,"minutes":57,"month":2,"seconds":39,"time":1332212259490,"timezoneOffset":0,"year":112}
我们可以获取d的time属性,并将它传递给new Date(),重新构造时间对象,如下:
var date = new Date(d.time);
这样就可以使用javascript的方式操作json返回的时间了