-1

when date is come is 3 days ago or not today how to calculate time difference b/w them. I want result in hh:mm:ss using moment in react native.

Final result like this: example if the clockin is 3 days ago from today then time will be 72:56:59 something like this.

I try to use this

var ax = moment( new Date().toLocaleString(), "DD/MM/YYYY HH:mm:ss" ).diff( moment( "27/02/2023 07:16:55", "DD/MM/YYYY HH:mm:ss" ) );

But not working.. Pls help. I try to solved last two days

riddhi
  • 7
  • 2

1 Answers1

0

Check this answer. You'd need to use asHours


var hours = duration.asHours();

You can do your own logic, or use libraries like momentJs or dateFns. I personally do not like using momentJs, since it is a big library.

NuttyJackJ
  • 235
  • 1
  • 9
  • let trackStartTime = props.actualTimeIn; let trackEndTime = curruntTime || moment().format("YYYY-MM-DD HH:mm:ss"); let overallActivity = moment.duration( moment(trackEndTime, "YYYY-MM-DD HH:mm:ss").diff( moment(trackStartTime, "YYYY-MM-DD HH:mm:ss") ) ); – riddhi Feb 28 '23 at 15:02
  • let hours = overallActivity.asHours(); hours = hours.toString().split(".")[0]; let miniutes = overallActivity.asMinutes(); miniutes = miniutes.toString().slice(0, 2); let seconds = overallActivity.asSeconds(); seconds = seconds. toString().slice(0, 2); const time = hours + ":" + miniutes + ":" + seconds; console.log("TIME IS", time); currentTime = time; setCurrentTime(time); – riddhi Feb 28 '23 at 15:03
  • Using above I got my exact difference the problem is I want to show my seconds in two digits so , seconds = seconds. toString().slice(0, 2); when I add this my timer not start automatically and when I not slice it timer work properly, but I want display seconds in two digits and timer also start... How to fix it pls help I am stuck last two days – riddhi Feb 28 '23 at 15:06