【发布时间】:2011-03-15 16:28:12
【问题描述】:
我有一个 twitter 提要,我创建了一个新的日期 obj,以便我可以根据自己的喜好格式化日期。
var created = new Date(this.created_at) 在 Firefox 和 chrome 中有效,但在 IE7 中无效。我似乎无法通过new Date() 函数传递日期。它只是返回 undefined 和 NaN。
这里是代码。如果您尝试对其进行测试,请不要忘记包含 jquery。谢谢。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Twitter Test</title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" >
$(function(){
$.getJSON("http://twitter.com/statuses/user_timeline/google.json?count=1&callback=?", function(data){
$.each(data, function(){
var created = new Date(this.created_at)
$("<div></div>").append("<ul><li>Unformatted: " + this.created_at + "</li><li>Formatted: " + created + "</li></ul>").appendTo("body")
});
})
})
</script>
</head>
<body>
</body>
</html>
【问题讨论】:
标签: javascript jquery json date twitter