Android Date Interval Get calcTimeBetween(Date start, Date end)

Here you can find the source of calcTimeBetween(Date start, Date end)

Description

calc Time Between

License

Open Source License

Declaration

public static String calcTimeBetween(Date start, Date end) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Date;

public class Main {
    public static String calcTimeBetween(Date start, Date end) {
        int SECOND = 1000;
        int MINUTE = SECOND * 60;
        int HOUR = MINUTE * 60;
        int DAY = HOUR * 24;

        int milliSeconds = Math.round(end.getTime() - start.getTime());

        if (milliSeconds > DAY) {
            return String.format("%d days", Math.round(milliSeconds / DAY));
        }/*from   w w w.ja  v a2s  .  c o  m*/

        if (milliSeconds < DAY && milliSeconds > HOUR) {
            return String.format("%d hours",
                    Math.round(milliSeconds / HOUR));
        }

        if (milliSeconds < HOUR) {
            return String.format("%d minutes",
                    Math.round(milliSeconds / MINUTE));
        }

        //Throw an exception instead?
        return null;
    }
}

Related

  1. calculatorDaysAgo(String date, Locale locale, String format)
  2. getFirstInterval(Context context, long lastupdate, long updateinterval)
  3. timeDifference(Date date)
  4. getTimeRangeStr(Date startDate, Date endDate)
  5. formatDuration(int duration)
  6. getOffectDay(long date1, long date2)
  7. getOffectDay(long date1, long date2)
  8. getOffectHour(long date1, long date2)
  9. getOffectHour(long date1, long date2)