Android Date Interval Get calculatorDaysAgo(String date, Locale locale, String format)

Here you can find the source of calculatorDaysAgo(String date, Locale locale, String format)

Description

calculator Days Ago

Declaration

public static long calculatorDaysAgo(String date, Locale locale,
        String format) 

Method Source Code

import android.annotation.SuppressLint;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class Main{
    //w w w .j  a  v  a 2s .  co m
    public static long calculatorDaysAgo(String date, Locale locale,
            String format) {
        Calendar today = Calendar.getInstance();
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat formatter = new SimpleDateFormat(format, locale);
        try {
            cal.setTime(formatter.parse(date));
        } catch (ParseException e) {
            DebugLog.e("ParseException");
            return 0;
        }
        return (today.getTimeInMillis() - cal.getTimeInMillis())
                / (24 * 60 * 60 * 1000);
    }
}

Related

  1. secondsBetween(Date dt1, Date dt2)
  2. getDateOffset()
  3. interval(Date date)
  4. checkIsIntervalDay(String startTime, String endTime)
  5. totalDays(Object o)
  6. getFirstInterval(Context context, long lastupdate, long updateinterval)
  7. timeDifference(Date date)
  8. getTimeRangeStr(Date startDate, Date endDate)
  9. formatDuration(int duration)