Find total hours between two Dates

前端 未结 11 1347
抹茶落季
抹茶落季 2020-11-28 06:00

I have two Date objects and I need to get the time difference so I can determine the total hours between them. They happen to be from the same day. The result I would like w

11条回答
  •  再見小時候
    2020-11-28 06:43

    This should work.

    long secs = (this.endDate.getTime() - this.startDate.getTime()) / 1000;
    int hours = secs / 3600;    
    secs = secs % 3600;
    int mins = secs / 60;
    secs = secs % 60;
    

提交回复
热议问题