javascript - 在 Day.js 减少倒数计时器的秒数时出现问题(尝试从 moment.js 迁移)
问题描述
我有一个关于倒数计时器的工作代码,使用Moment.JS
--> [他的代码:https ://codepen.io/javanigus/pen/KrMRvd ]。
我试图使用Day.JS复制它,你可以说我想将它从 moment.js 迁移到 day.js 。我成功迁移它,直到用当前(日期+时间)减去目标(日期+时间)。它出现在控制台日志中。
--> [我的代码:https ://codepen.io/justreadthis/pen/bGVvvXP ]。
但是现在当我想用 1 秒减去我的最后一个代码部分时,我卡住了(下一步将使它不断地减去,对吗?)。我尝试console.log(dayjs.preciseDiff(duration, interval, true));
将间隔值设置为 1 秒,它会将数据变为 NaN。
有谁知道如何使它工作?我试图不使用moment.js,因为如果可能的话我想坚持使用day.js。
谢谢
------------------------编辑------------------------
我现在卡住的当前javascript代码,它给出了NaN值。
再次编辑,我将 JS 文件放入 HTML 中很容易从这里看到,而不是从 codepen。
.
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script src="https://unpkg.com/dayjs-plugin-utc"></script>
<script src="https://unpkg.com/dayjs-precise-range@1.0.1/precise-range.js"></script>
<time></time>
<script>
var eventTime, currentTime, interval, duration;
dayjs.extend(dayjsPluginUTC.default);
dayjs.extend(preciseDiff);
interval = 1;
eventTime = dayjs('2020-05-15T07:59:50+00:00').format();
// based on time set in user's computer time / OS
currentTime = dayjs.utc().format();
// get duration between two times
duration = dayjs.preciseDiff(eventTime, currentTime ,true);
console.log(dayjs.preciseDiff(duration, interval, true));
</script>
解决方案
推荐阅读
- python-3.x - Python 3 matplotlib 添加具有多个比例轴的水印
- python - 在 python GUI 中显示打印输出?
- hadoop - 在伪分布式模式下启动 HBase 失败抛出“Failed construction RegionServer”
- javascript - ServiceNow - 列表仅使用最后一个值更新
- javascript - 如何在删除包含 discord.js 的嵌入之前设置延迟?
- java - Spring Boot addObject 无法正常工作
- python - 我不知道如何在 PyCharm 中安装熊猫
- assembly - 在 x86_64 中,如果条件为假,32 位 cmov 是否会清除最高位?
- php - Laravel - SQLSTATE [23000]:完整性约束违规:1062 键“posts_user_id_unique”的重复条目“1”
- android - 背景/文本大小调整问题