2

I want to put the following string: '10-10-2013 03:04' in a Date object. It's working in Chrome but Firefox tells me it's an invalid Date. (I guess they mean format?) I tried to use Date.parse on it but that makes it a NaN.

What to do?

UPDATE: I used the answer of thefourtheye, but now Chrome actually says it's an invalid date ..

var dateString = '10-10-2013 03:04';
dateString = dateString.replace(/-/g, ' ');
var DateToUse = new Date(dateString);

Returns an invalid date in Chrome.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Anoniem Anoniem
  • 1,915
  • 6
  • 18
  • 19
  • I think this post will solve your problem: http://stackoverflow.com/questions/4321270/regarding-javascript-new-date-and-date-parse – Pradeep shyam Oct 10 '13 at 07:15

1 Answers1

4
<script>
    var myDate = new Date("10 10 2013 03:04");
    console.log(myDate);
</script>

According to the standard, https://www.rfc-editor.org/rfc/rfc2822#page-14, space can be used to separate date, month and year. The above example works perfectly in Chrome and Firefox.

Community
  • 1
  • 1
thefourtheye
  • 233,700
  • 52
  • 457
  • 497