我们在通过json方法获取后台数据的时候,如果返回的其中一个数据是时间类型。那么JSON将会把这时间类型的数据序列化成类似于"1278903921551"的字符串.
如何转化成我们想要的时间格式呢?直接上代码
function ChangeDateFormat(cellval) { cellval = "1278903921551"; var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10)); alert(date); 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; }