0

I have a working code from someone about countdown timer using Moment.JS
--> [his code: https://codepen.io/javanigus/pen/KrMRvd ] .
Im trying to replicate it using Day.JS, you could say i want to migrate it from moment.js to day.js . I success to migrate it until substract target (date+time) with current (date+time). It appear in console log.
--> [my code: https://codepen.io/justreadthis/pen/bGVvvXP ].
But now im stuck when i want to substract my last code part with 1 second (next step would make it continously substract, right ?). I try console.log(dayjs.preciseDiff(duration, interval, true)); with interval value I set to 1 second, it would get the data to NaN.

Does anyone know how to make it works ? Im trying to not used moment.js, as I want to stick using day.js if possible.
Thanks
------------------------edit------------------------
my current javascript code that i stuck now, it give NaN value. edit again, i put JS file into HTML to make is easly to see from here, not from 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>

0 Answers0