Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TimeCalculation {
- public int calculateDifference(String timeFrom, String timeTo){
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
- Date startDate = simpleDateFormat.parse("22:00");
- Date endDate = simpleDateFormat.parse("07:00");
- long difference = endDate.getTime() - startDate.getTime();
- if(difference<0)
- {
- Date dateMax = simpleDateFormat.parse("24:00");
- Date dateMin = simpleDateFormat.parse("00:00");
- difference=(dateMax.getTime() -startDate.getTime() )+(endDate.getTime()-dateMin.getTime());
- }
- int days = (int) (difference / (1000*60*60*24));
- int hours = (int) ((difference - (1000*60*60*24*days)) / (1000*60*60));
- int min = (int) (difference - (1000*60*60*24*days) - (1000*60*60*hours)) / (1000*60);
- Log.i("log_tag","Hours: "+hours+", Mins: "+min);
- return hours;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement