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?

有帮助吗?

解决方案

try this

var date = new Date(Number.parseFloat('/Date(1317772800000)/'.substring(6)));
var newdate = date.getMonth() +' ' +date.getDate() +' ' +date.getFullYear()

其他提示

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)

Try using moment.js i.e.:

moment().format('MMMM Do YYYY, h:mm:ss a')

Then you can do:

moment(1317772800000).format("MMM Do YY");

Try this

unixtime = 1317772800000;
var newDate = new Date();
newDate.setTime(unixtime);
dateString = newDate.toUTCString();

alert(dateString);

DEMO

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top