1

I have a case where I need to check the diff of the hours between two Date-time. I am new in typescript but in java, I have done something like below just a small example to show you what I need.

  int hours = (int) ChronoUnit.HOURS.between(app.getDisableAt(), LocalDateTime.now(Clock.systemUTC()));

And I need the same thing but in front-end. By this, I get the hour's diff correctly, but I don't want to save in database so I prefer the front-end.

Ilia Tapia
  • 629
  • 3
  • 10
  • 23

1 Answers1

1

Convert into epoch date and get difference between two dates and divide by 1000*3600

getDateDiffInHours(date1: Date, date2: Date) {
        return Math.floor((new Date(date2).getTime() - new Date(date1).getTime()) / 3600000);
      }
Chaitanya
  • 847
  • 1
  • 8
  • 15
  • I accept your answer can you please upvote my post cause I want to have the opportunity to ask more question in the future thank you a lot – Ilia Tapia Aug 07 '19 at 08:26