Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript invalid date in iOS/Android 2.2

I have this string containing a date I need to parse to get a Date javascript object. It works if I execute the code in a PC browser but gives me an invalid date if I run the web page in a iOS (tried iPhone 4.3) and Android 2.2 emulator.

<body>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</head>
<html>
<script type="text/javascript">
$(document).ready(function(){
  var date = new Date('2011-03-04T08:14:00+01:00');
  $('#test').html(date.toString());
});
</script>
<div id="test"></div>
</html>
</body>

Does anybody know what may be wrong? I can always parse the date manually (considering it'll always be in the same format) but anyways it seems like a strage problem to me.

Cheers!

like image 903
brafales Avatar asked Nov 06 '22 00:11

brafales


1 Answers

The date actually is invalid:

tjwebb@latitude:~$ rhino
Rhino 1.7 release 2 2010 09 15
js> var date = new Date('2011-03-04T08:14:00+01:00');
js> date.toString();
Invalid Date
js> 

This is using Rhino, Mozilla's javascript engine, which is about as "standard" as it gets.

-tjw

like image 144
Travis Webb Avatar answered Nov 09 '22 11:11

Travis Webb