gpt4 book ai didi

javascript - countdown.js 其他格式

转载 作者:行者123 更新时间:2023-12-03 12:24:57 24 4
gpt4 key购买 nike

我正在使用 http://countdownjs.org/ 中的非常好的脚本几乎一切都运转良好。但是,我想要没有字符串 小时、分钟、秒的格式 - 只是一个普通的计时器(hh:mm:ss)。我正在考虑使用正则表达式,但我想这是非常无效的。那么有没有更好的办法呢?这是我到目前为止的代码(有效,但效率非常低):

var now = new Date();
var totalEnd = now.setHours(now.getHours() + 8);
var timeString = countdown( null, totalEnd, countdown.HOURS|countdown.MINUTES|countdown.SECONDS ).toString();
if (timeString) {
timeString = timeString.replace(/\s?hours?,|\s?minutes?,/gi, ':');
timeString = timeString.replace(/\s|and|seconds?/gi, '');
// now I have a timestring with hh:mm:ss
// but I want to avoid the regex
}

最佳答案

为什么将其放入字符串而不是使用给定的对象?然后,您将能够获得所需的变量,而无需进行一些字符串替换。例如:

var now = new Date();
var totalEnd = now.setHours(now.getHours() + 8);
var time = countdown( null, totalEnd, countdown.HOURS|countdown.MINUTES|countdown.SECONDS );
alert(time.days);

关于javascript - countdown.js 其他格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24253174/

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