1

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?

2
  • 3
    Start by using new Date(datestr); Commented May 15, 2014 at 12:52
  • I guess your trying to evaluate that string then what about using eval as in: eval("/Date(1317772800000)/".replace('/','')); Commented May 15, 2014 at 12:57

4 Answers 4

3

try this

var date = new Date(Number.parseFloat('/Date(1317772800000)/'.substring(6)));
var newdate = date.getMonth() +' ' +date.getDate() +' ' +date.getFullYear()
Sign up to request clarification or add additional context in comments.

Comments

3

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)

Comments

2

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");

Comments

1

Try this

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

alert(dateString);

DEMO

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.