How to get month from string in javascript
I have a date in a line: var myDateStr='1431451872338.00';
I want getMonth () from this format date, I do: var date = new Date(myDateStr);
but always return the wrong date.
and the getMont () method always returns NaN if I put this: var date = new Date(1431451872338.00);
this will return the date correctly, but with my string it doesn't
my var myDateStr gets the value from json and is a variable, if someone can help me, thank you in advance, I hope you can understand
source to share
When you pass a date string to a javascript date object, it should be in the format "yyyy / mm / dd" or something like "Jan 10, 2014". What you are going through is the number of milliseconds since Jan 1, 1970 that is only accepted by the date object as a number. You need to change the type of the input variable.
Please be sure to research carefully before answering questions - the answer to your question is clearly indicated in many date references such as this one .
source to share