简体   繁体   中英

calculate time difference in nodeJs

I am new to nodejs, and I am trying to get the difference between 2 times, but I get a different value. here is my code :

         var now = moment(Suivi.FI);
         var then = moment(Suivi.DI);
         var TA = moment(moment.duration(then.diff(now))).format("hh:mm");

as a result i get:

sql": "Insert into suivi(date, equipement, project, shift, description, Action, user, DA, DI, FI,TA) values('','','','','','','','','','','12:00')"

I tried to test with a simple date but I got the same value. what am I missing? what should I do.?

you can use .format("hh:mm")

for simple time differnce:

var TA = now.diff(then);

this will give you more flexibility for formating (see docs ):

var TA = moment.duration(now.diff(then));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM