javascript - 在倒计时脚本上设置 GMT
问题描述
如何将 GMT 设置为 date.Now()?
var countDownDate = getNextDayOfWeek(new Date(),0,21);
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24)).toString();
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)).toString();
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)).toString();
var seconds = Math.floor((distance % (1000 * 60)) / 1000).toString();
// Add 0 when value are < 10
hours = (hours < 10) ? "0"+hours : hours;
minutes = (minutes < 10) ? "0"+minutes : minutes;
seconds = (seconds < 10) ? "0"+seconds : seconds;
var grb = jq("#grb");
// Display the result in the element with id="grb"
grb.html(days + "d " + hours + "h " + minutes + "m " + seconds + "s");
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
var one_hour = -60 * -60 * -1000;
if(distance < one_hour){
grb.html("GRB is finished!");
}else{
grb.html("GRB is open!");
}
}
}, 1000);
});
它一直使用您计算机的时间,我想每次都使用时区来存储。
我已经尝试过 TimeZoneOffset,但没有奏效,任何帮助将不胜感激。
解决方案
请看这个
var now = new Date();
var nowUTC = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
var distance = end - nowUTC;
推荐阅读
- jquery - Dropzone maxFilesize 上的错误
- javascript - Javascript 决策语句无法正常工作
- algorithm - 为什么时间复杂度是 T(n) = 2n^2 + n + 1?
- jdbc - MyBatis 中的 session 和 connection 有什么区别?
- javascript - 我的 Vue chrome 扩展无法在生产模式下工作。错误是:“无法建立连接。接收端不存在”
- nginx - Nginx RTMP 模块不保存直播文件
- python-3.x - 我如何使用 CNN 和 RNN LSTM 进行二元分类
- python - 如何将 Python 中数据框的列值传递给 Oracle SQL 脚本
- css - 滤镜功能和滤镜效果
- ibm-cloud - 如何制作或添加 13 种默认语言以外的 ibm watson 语言