1

I'm trying to take a date in a string and convert it to a unix timestamp int. I'm using parseInt to change the string to an int and it works fine in chrome. But IE and Edge give me NaN.

Here it is in jsfiddle: http://jsfiddle.net/padv54s9/2/

var dob = (+new Date('2012.03.1')/1000).toFixed(0);
dob = parseInt(dob);
alert(dob);
Web_Designer
  • 72,308
  • 93
  • 206
  • 262
user2874270
  • 1,312
  • 2
  • 18
  • 31
  • 2
    Check that your browser understands the date format you're trying to use -- `console.log(Date.parse('2012.03.1'))`. Support for various formats is almost entirely up to each engine to choose/provide. JavaScript only specifies one as guaranteed -- [`YYYY-MM-DDThh:mm:ss.sTZD`](http://www.w3.org/TR/NOTE-datetime) – Jonathan Lonowski Oct 17 '15 at 18:37
  • 1
    @JonathanLonowski Thanks! It wasn't understanding the date format. changed it from . to / and it worked – user2874270 Oct 17 '15 at 18:43

1 Answers1

1

The problem is that IE and Edge don't understand dates in yyyy.mm.dd format. However, they do understand dates in yyyy/mm/dd format. Changing the . to / fixes the problem

user2874270
  • 1,312
  • 2
  • 18
  • 31
  • Don't use `/` either – it might work, but it's non-standard so it's not guaranteed. Either use `-` or even better build the date with numbers (`new Date( 2012, 3, 1 )`) – JJJ Oct 17 '15 at 18:48