目前我们有这个代码,除了需要使用指定的时区而不是用户的时区外,它有效:
$('#countdown').countdown('<?PHP echo $date_end?>').on('update.countdown',function(event) {
var format = '%-S second%!S';
if (event.offset.years > 0 || event.offset.weeks > 0 || event.offset.days > 0 || event.offset.hours > 0 || event.offset.minutes > 0) {
if(event.offset.minutes > 0) {
format = '%-M minute%!M ' + format;
}
if(event.offset.hours > 0) {
format = '%-H hour%!H ' + format;
}
if(event.offset.days > 0) {
format = '%-d day%!d ' + format;
}
if(event.offset.weeks > 0) {
format = '%-w week%!w ' + format;
}
}
$(this).html(event.strftime(format));
}).on('finish.countdown',function(event) {
$(this).html('Finished');
});
我已经看到了几个添加时区的例子,但没有一个像我们一样使用jquery倒计时插件.
关于如何添加10作为当前时区的任何想法?所以它使用它而不是用户的时区?
谢谢.
解决方法
我猜你正在使用
https://github.com/hilios/jQuery.countdown,因为它没有时区选项来使用它.
我使用moment.js和moment-timezone-with-data.js(包含所有时区)来处理时区.
<div data-countdown="2015/05/20" data-zone="US/Central" class="countdown"></div>
函数将日期转换为适当的时区并以毫秒为单位返回
var timefun = function (countdown,zone){
var date = moment.tz(countdown,"YYYY/MM/DD",zone);
return date.valueOf();
}
利用上面的函数将毫秒作为参数传递给jQuery.countdown()
$(".countdown").countdown(timefun($(".countdown").data("countdown"),$(".countdown").data("zone")))
例:
http://jsfiddle.net/heLrsnqx/2/
如果您使用的是http://keith-wood.name/countdown.html,请参阅以下示例
例:
http://jsfiddle.net/w1oyv8kv/