Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

javascript - 使用Moment.js转换天以获取两个日期的小时,分??钟和秒(Convert days to get hours, minutes and seconds of two dates using momentjs)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...