Reputation: 46750
I have this string in Javascript
"/Date(1317772800000)/"
and I'd like to display it as a meaningful date in my page. Currently, when I output the variable that contains this date I get the following displayed on my page
/Date(1317772800000)/
What I'd like is to display this in the format DD MM YYYY like so
10 05 2011
How is this possible?
Upvotes: 1
Views: 217
Reputation: 763
try this
var date = new Date(Number.parseFloat('/Date(1317772800000)/'.substring(6)));
var newdate = date.getMonth() +' ' +date.getDate() +' ' +date.getFullYear()
Upvotes: 3
Reputation: 1069
If you have your date in a string provided then first you need to extract the number:
var strDate = "/Date(1317772800000)/";
var dateInt = strDate.replace("/Date(","").replace(")/","");
var date = new Date(parseInt(dateInt))
This gives you a JavaScript date object that you can do pretty much a lot with, if you want simple check just execute:
alert(date)
Upvotes: 3
Reputation: 266
Try this
unixtime = 1317772800000;
var newDate = new Date();
newDate.setTime(unixtime);
dateString = newDate.toUTCString();
alert(dateString);
Upvotes: 1