junaidp
junaidp

Reputation: 11201

java: compare time/date and get the correct format of time difference

I have these two times

2011-9-5 0:00
2011-9-5 15:50

when i get there time difference by

Date d1=df.parse(interviewList.get(28).getTime());
Date d2=df.parse(interviewList.get(29).getTime());
long d1Ms=d1.getTime();
long d2Ms=d2.getTime();
diff =  Math.abs((d1Ms-d2Ms)/60000);

it gives me correct difference but the difference coming is 950
How can i get it in a proper format like 15:50 ( which is the diff of above two)

Thanks

Upvotes: 0

Views: 318

Answers (1)

Jigar Joshi
Jigar Joshi

Reputation: 240900

It gives you correct difference,

950 minute = 15 hour and 50 min

you can achieve this by

int hour = totalMinutes / 60;
int minute = totalMinutes - (hour * 60);

and then

String dispString = hour + ":" + minute;

Upvotes: 3

Related Questions