Possible Duplicate:
Convert a date to string in Javascript
I have date in json format at client side :
/Date(1352745000000)/
The code which i have tried to parse Json date:
eval(dateTime.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
and
new Date(parseInt(dateTime.substr(6)));
Out put I am getting:
Tue Nov 27 2012 00:00:00 GMT+0530 (India Standard Time)
Desire Output
2012-11-27 11:16
I am not able to figure out how we will get this.
var date = new Date(parseInt(dateTime.substr(6)));
var formatted = date.getFullYear() + "-" +
("0" + (date.getMonth() + 1)).slice(-2) + "-" +
("0" + date.getDate()).slice(-2) + " " + date.getHours() + ":" +
date.getMinutes();
Best not to try save space with this one :)
var str, year, month, day, hour, minute, d, finalDate;
str = "/Date(1352745000000)/".replace(/\D/g, "");
d = new Date( parseInt( str ) );
year = d.getFullYear();
month = pad( d.getMonth() + 1 );
day = pad( d.getDate() );
hour = pad( d.getHours() );
minutes = pad( d.getMinutes() );
finalDate = year + "-" + month + "-" + day + " " + hour + ":" + minutes;
function pad( num ) {
num = "0" + num;
return num.slice( -2 );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With