Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在倒计时脚本上设置GMT_Javascript_Timer_Timezone_Countdown - Fatal编程技术网

Javascript 在倒计时脚本上设置GMT

Javascript 在倒计时脚本上设置GMT,javascript,timer,timezone,countdown,Javascript,Timer,Timezone,Countdown,如何将GMT设置为date.Now() var countDownDate=getNextDayOfWeek(新日期(),0,21); //每1秒更新一次倒计时 var x=setInterval(函数(){ //获取今天的日期和时间 var now=new Date().getTime(); //找出现在和倒计时日期之间的距离 var距离=倒计时日期-现在; //天、小时、分钟和秒的时间计算 变量天数=数学楼层(距离/(1000*60*60*24)).toString(); 变量小时数=数学楼

如何将GMT设置为date.Now()

var countDownDate=getNextDayOfWeek(新日期(),0,21);
//每1秒更新一次倒计时
var x=setInterval(函数(){
//获取今天的日期和时间
var now=new Date().getTime();
//找出现在和倒计时日期之间的距离
var距离=倒计时日期-现在;
//天、小时、分钟和秒的时间计算
变量天数=数学楼层(距离/(1000*60*60*24)).toString();
变量小时数=数学楼层((距离%(1000*60*60*24))/(1000*60*60)).toString();
变量分钟数=数学楼层((距离%(1000*60*60))/(1000*60)).toString();
var seconds=数学地板((距离%(1000*60))/1000).toString();
//当值小于10时,加0
小时数=(小时数<10)?“0”+小时数:小时数;
分钟=(分钟<10)?“0”+分钟:分钟;
秒=(秒<10)?“0”+秒:秒;
var grb=jq(“grb”);
//在id为=“grb”的元素中显示结果
html(天+天+小时+小时+分钟+米+秒+秒);
//如果倒计时结束,写一些文字
如果(距离<0){
净间隔(x);
一小时变量=-60*-60*-1000;
如果(距离<一小时){
html(“grb完成了!”);
}否则{
html(“grb已打开!”);
}
}
}, 1000);
}))

它一直在使用你电脑的时间,我想每次都使用一个时区来存储

我尝试了时区偏移,但没有成功,如果有任何帮助,我们将不胜感激。

请查看此内容

var now = new Date();
var nowUTC = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
var distance = end - nowUTC;

getNextDayOfWeek返回什么?使用间隔为1000的setInterval不能保证它将以精确的1秒间隔运行。在实行夏时制的地方,白天并不都是24小时。getTimezoneOffset方法根据主机系统设置返回时区偏移量,它与日期对象不关联。日期没有时区偏移属性,您不能设置它。@Blutengel-您的代码中没有任何与本地时间相关的内容。请显示
getNextDayOfWeek
的实现。您的问题可能会在那里得到解决。仅使用代码的答案没有帮助。您应该解释OP出现问题的原因,以及您的代码如何修复它。您好,它不工作,因为它没有显示GMT+8。
var now = new Date();
var nowUTC = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
var distance = end - nowUTC;