我见过其他例子,但如果可能,我正在寻找这种特定格式?
答案 0 :(得分:7)
以下是使用jQuery从JSON日期格式到所需日期格式的快速格式:
对于JSON日期字符串,如:
/Date(1339439400000)/
尝试:
var newFormattedDate = $.datepicker.formatDate('mm/dd/yy', new Date(Date(your_JSON_date_string)));
它将导致如下日期: 罚金。
答案 1 :(得分:6)
function formatJsonDate(jsonDate) {
return (new Date(parseInt(jsonDate.substr(6)))).format("dd/mm/yyyy");
};
var testJsonDate = formatJsonDate('/Date(1224043200000)/');
alert(testJsonDate);
答案 2 :(得分:1)
没有“json日期格式”。 json只返回字符串。
日期javascript对象可以解析各种格式。请参阅the documentation。
你可以这样做:
var myDate = new Date(myDateAsString);
答案 3 :(得分:0)
这篇文章的答案中有一些建议 - How do I format a Microsoft JSON date?
如果这些示例不起作用,您可以手动格式化。这是一个演示它的快速小提琴 - http://jsfiddle.net/dhoerster/KqyDv/
$(document).ready(function() {
//set up my JSON-formatted string...
var myDate = new Date(2011,2,9);
var myObj = { "theDate" : myDate };
var myDateJson = JSON.stringify(myObj);
//parse the JSON-formatted string to an object
var myNewObj = JSON.parse(myDateJson);
//get the date, create a new Date object, and manually format the date string
var myNewDate = new Date(myNewObj.theDate);
alert(myNewDate.getDate() + "/" + (myNewDate.getMonth()+1) + "/" + myNewDate.getFullYear());
});