开发者

Javascript invalid date in iOS/Android 2.2

开发者 https://www.devze.com 2023-02-19 03:37 出处:网络
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

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>
<s开发者_JAVA百科cript 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!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号