How to convert days to get the hours, minutes and seconds using momentjs?
(如何使用momentjs转换天数以获得小时,分钟和秒?)
I think my calculation is wrong because I'm getting the difference of date today and date that I'm getting from the API which has 5days.(我认为我的计算是错误的,因为我得到的是今天的日期和从具有5天的API中获得的日期之差。)
So far this is my code
(到目前为止,这是我的代码)
const countdown = () => {
let dueDate = '2019-12-04 12:50:42 AM'; //getting this value from the API
let eventTime = moment(dateDue).unix();
let currentTime = moment(new Date()).unix();
let diffTime = eventTime - currentTime;
const interval = 1000;
let duration = moment.duration(diffTime * interval, 'milliseconds');
duration = moment.duration(duration - interval, 'milliseconds');
countDowntimer[dateDue] = setInterval(() => {
setMinutes(duration.minutes());
setSeconds(duration.seconds());
}, interval);
return `${duration.hours()}hr ${duration.minutes()}m ${duration.seconds()}s`;
};
const timer = countdown(minutes, seconds);
return timer;
ask by Alyssa Reyes translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…