iOS / Android 2.2中的Javascript无效日期 [英] Javascript invalid date in iOS/Android 2.2

查看:68
本文介绍了iOS / Android 2.2中的Javascript无效日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,其中包含我需要解析以获得Date javascript对象的日期。如果我在PC浏览器中执行代码,它会起作用,但是如果我在iOS(试用iPhone 4.3)和Android 2.2模拟器中运行网页,则会给我一个无效的日期。

 < 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');
$('#测试').html(date.toString());
});
< / script>
< div id = test>< / div>
< / html>
< / body>

有人知道什么可能是错的吗?我总是可以手动解析日期(考虑到它总是采用相同的格式),但无论如何对我来说似乎是一个战略问题。



干杯!

解决方案

实际上日期无效:

  tjwebb @ latitude:〜$ rhino 
Rhino 1.7版本2 2010年9月15日
js> var date = new Date(’2011-03-04T08:14:00 + 01:00’);
js> date.toString();
无效日期
js>

这是使用Rhino(Mozilla的JavaScript引擎),它的功能与标准版本差不多。 / p>

-tjw


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!

解决方案

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

这篇关于iOS / Android 2.2中的Javascript无效日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆