Firefoxx Pwnass
Firefoxx Pwnass

Reputation: 135

Calculate difference in time (between current and next day)

There is a lot of similar topics but I couldn't find something similar then my problem. I've found only how to calculate if for example second time is greater then first time, like:

  1. 22:00
  2. 23:00

The result is easy to get. Just subtract second time with first using Date API. Difference is in milliseconds and you can easily convert them in seconds/minutes..

What I want to know, how to get difference between time in first day and time in second day, for example:

  1. 22:25
  2. 06:30

Difference should be 8 hours and 5 minutes.

Or another example

  1. 19:00
  2. 00:00

Difference should be 5 hours.

How to calculate time in this way? Any help is appreciated.

Upvotes: 1

Views: 1198

Answers (2)

Buda Gavril
Buda Gavril

Reputation: 21657

Use Calendar class. Set your day, hour and minutes and finally subtract those dates (in milliseconds) and you will convert result in hour, minutes and seconds.

Upvotes: 0

Andrei Zhukouski
Andrei Zhukouski

Reputation: 3506

Convert your date and time to TimeStamp (It's just the long representation of a date in milliseconds since Jan. 1, 1970.), then calculate difference, and transferred from milliseconds to hours.

Also check this

Upvotes: 1

Related Questions