13
Date.parse();

My jsFiddle works fine, but run it in my ide (both Aptana and WebStorm) shows NaN in the console.log() output.

Really confused about this... Has someone had such experience before?

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
sozhen
  • 7,627
  • 14
  • 36
  • 53

3 Answers3

26

Working demo http://jsfiddle.net/7KfuM/

Change - to /

Good read: Jquery Date.parse returning NaN in Chrome browser? or https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date

Try this:

var firstDayTimestamp = Date.parse("2009/07/13 00:00:00" + "-0500") / 1000;

Hope this fits the cause! B-)

Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
2

The date should be in the IETF date syntax (RFC2822 Section 3.3) format, e.g. "Mon, 25 Dec 1995 13:30:00 GMT", or "Mon, 25 Dec 1995 13:30:00 GMT+0430".

Read more: Date.parse()

Surprisingly this should be done also for the current (2017) versions of IE (11.x) and FF (56.x) for the Date.parse to work correctly.

Nicolapps
  • 819
  • 13
  • 29
Picard
  • 3,745
  • 3
  • 41
  • 50
0

Date.parse will not work for format dd/mm/yyyy so when format is dd/mm/yyyy 0r dd-mm-yyyy just reverse it

var char = date.charAt(2);//return '/' or '-'

Date.parse(date.split(char).reverse().join(char));

it wil change format to yyyy/mm/dd and parse it