Reputation: 855
Hi I have a scenario where I need to convert the JSON response to a date object so that I can display it in different format. Here is the JSON response what I am getting:
responseData: [{"id":10,"createdDate":"1 Sep, 2014 12:48:52 PM"}]
In the UI i need display create date as 1 Sep, 2014 or I need to display it in mm-dd-yyyy formate. How can I do this? Do I need to create date object from json response or I should play around with parsing the json reponse? Any help greatly appreciated.
Upvotes: 0
Views: 154
Reputation: 9947
pass data.createdDate
to renderdate
function
function renderDate(value) {
var getDate;
if (Date.parse(value)) {
getDate = new Date(value);
}
//used for json date format like /Date(1224043200000)/
else {
getDate = new Date(parseInt(value.substr(6)));
}
return ((getDate.getMonth() + 1) + "-" + getDate.getDate() + "-" + getDate.getFullYear());
}
Upvotes: 0
Reputation: 3456
Try this code hope works
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var date = day + "/" + month + "/" + year
alert(date);
Upvotes: 1
Reputation: 3045
Manipulate date object after creating json obj as follows -->
new Date(JSON.parse('[{"id":10,"createdDate":"1 Sep, 2014 12:48:52 PM"}]')[0].createdDate)
Upvotes: 0