我有一个简单的计时器倒计时HTML页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<title>Countdown</title>
<style type="text/css">
@import "http://keith-wood.name/css/jquery.countdown.css";
#defaultCountdown { width: 240px; height: 45px; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://keith-wood.name/js/jquery.countdown.js"></script>
<script type="text/javascript">
$(function () {
var austDay = new Date();
austDay = new Date("December 9, 2011 11:30:00");
$('#defaultCountdown').countdown({until: austDay});
$('#year').text(2011);
});
</script>
</head>
<body>
<h2>Countdown</h2>
<p>Counting down to 11:30am Dec 9th, <span id="year">2011</span>.</p>
<div id="defaultCountdown"></div>
</body>
</html>
问题是它无法正确处理时区。例如,它显示了我的时区中的正确倒计时,但如果有人在CST中查看它,那么它会关闭2个小时。在Javascript代码中设置Date
的正确方法是什么?现在,我有这个
austDay = new Date("December 9, 2011 11:30:00");
答案 0 :(得分:1)
不确定这将如何与倒计时插件进行互动...
austDay = new Date(Date.UTC(year, month, day, hour, minute, second));
答案 1 :(得分:1)
您可以执行以下操作:
var tz = d.getTimezoneOffset();
var date = new Date("December 9, 2011 11:30:00");
austDay = date.setMinutes( date.getMinutes() + tz );