I have 2 hours in day, and when i subtracting time I just only get hour value, hour and minute is long data type. How can get hour and minute?
example: 10:10 today - 7:45 tomorrow = 21 hour and 35 minute
I have 2 hours in day, and when i subtracting time I just only get hour value, hour and minute is long data type. How can get hour and minute?
example: 10:10 today - 7:45 tomorrow = 21 hour and 35 minute
You can use SimpleDateFormat class to give a complete date info:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date startDate = df.parse("2016-05-24 17:50:10");
Date endDate = df.parse("2016-05-25 19:05:15");
long diff = endDate.getTime() - startDate.getTime();
int timeInSeconds = (int) (diff / 1000);
int hours, minutes, seconds;
hours = timeInSeconds / 3600;
timeInSeconds = timeInSeconds - (hours * 3600);
minutes = timeInSeconds / 60;
timeInSeconds = timeInSeconds - (minutes * 60);
seconds = timeInSeconds;
System.out.println(String.format("%d:%d':%d\"", hours, minutes, seconds));