gpt4 book ai didi

javascript - jQuery 倒计时获取 10 之前的时间 :00 am today or tomorrow

转载 作者:行者123 更新时间:2023-12-01 03:37:33 25 4
gpt4 key购买 nike

我需要一个小脚本,但我有点困惑。

我想使用这个插件:http://keith-wood.name/countdown.html

目标:进行倒计时,从现在开始计算到上午 10:00 - 如果是上午 0-9:59:59,则计算到今天的 10 点;如果是在 10:00:00 之后,则计算到明天的 10:00 。这样可以理解吗?

这是我需要的 javascript/jquery(我知道这行不通):

var currentDate = new Date(new Date().getTime());
var hours = currentDate.getHours();
var endTime;
if(hours >= 10){
endTime = give me next day 10:00
} else {
endTime = give me this day 10:00
}
$("#countdown").countdown({until: endTime, format: 'HMS'});

最佳答案

以下内容应该有效(console.log() 是出于测试目的而添加的)。请注意,它将使用浏览器时区而不是 UTC 时间。

var currentDate = new Date(new Date().getTime());
var hours = currentDate.getHours();
var endTime = new Date(currentDate);
endTime.setMinutes(0);
endTime.setSeconds(0);
endTime.setHours(10);

if(hours >= 10){
endTime.setDate(endTime.getDate() + 1);
}
console.log(endTime);
$("#countdown").countdown({until: endTime, format: 'HMS'});

关于javascript - jQuery 倒计时获取 10 之前的时间 :00 am today or tomorrow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44152651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com