1

I have datetime as string, fxp:

2014-11-10 12:12 

And I need create from this string Date object with correctly set months (in object months starting from 0).

So i tried this:

 var d = Date.parse("2014-11-10 12:12");

But it seems to be not working.

 console.log("Month is " + d.getMonth());

Is not giving result.

How can i parse and create date object from string correctly?

Thanks for any help.

1
  • 1
    Not really an answer, but I always link anybody dealing with date parsing in js to this library. momentjs.com Commented Sep 23, 2014 at 14:29

1 Answer 1

1

Date.parse method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.

You cant parse the Month from that value. You have to use a new Date object.

Try:

var d = new Date("2014-11-10 12:12");
console.log("Month is " + d.getMonth());
Sign up to request clarification or add additional context in comments.

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.