0

我有一个关于倒数计时器的工作代码,使用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>

4

0 回答 0