Currently utilizing countdown.js
for a project where I need to add 60 days
to a date
fetched from the database. Successfully implemented this in the targetDay
variable and it's functioning properly. However, when attempting to calculate this date from the current date, an unexpected result of
"1969-11-05T21:24:07.416Z"
is being returned - why?
const nowDate = moment();
const targetDay = moment('2020-10-24 14:25:26').add('60', 'days');
const countdown = moment(nowDate - targetDay);
console.log(countdown);
//const diff = targetDay.fromNow();
const count_days = countdown.format('D');
const count_hours = countdown.format('HH');
const count_minutes = countdown.format('mm');
const count_seconds = countdown.format('ss');
console.log(count_days + ' days:' + count_hours + ' hrs:' + count_minutes + ' m:' + count_seconds + ' s');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
Experimented with the fromNow()
function, but it only returns as a string
. My objective is to create a countdown to the target day starting from the present time.