Reputation: 8504
I have a simple timer countdown HTML page
<!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>
Problem is that it doesn't handle timezones properly. For example, it shows the correct countdown in my timezone but if someone views it from say in CST, it's off by 2 hours. What's the proper way to set the Date
in the Javascript code? Right now, I have this
austDay = new Date("December 9, 2011 11:30:00");
Upvotes: 1
Views: 2227
Reputation: 914
You can do something like:
var tz = d.getTimezoneOffset();
var date = new Date("December 9, 2011 11:30:00");
austDay = date.setMinutes( date.getMinutes() + tz );
Upvotes: 1
Reputation: 7035
Not sure how this will interact with the countdown plugin...
austDay = new Date(Date.UTC(year, month, day, hour, minute, second));
Upvotes: 1