Android Utililty Methods Date Interval Get

List of utility methods to do Date Interval Get

Description

The list of methods to do Date Interval Get are organized into topic(s).

Method

intgetOffectHour(long date1, long date2)
get Offect Hour
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
int h1 = calendar1.get(Calendar.HOUR_OF_DAY);
int h2 = calendar2.get(Calendar.HOUR_OF_DAY);
int h = 0;
int day = getOffectDay(date1, date2);
...
intgetOffectHour(long date1, long date2)
get Offect Hour
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
int h1 = calendar1.get(Calendar.HOUR_OF_DAY);
int h2 = calendar2.get(Calendar.HOUR_OF_DAY);
int h = 0;
int day = getOffectDay(date1, date2);
...
intgetOffectMinutes(long date1, long date2)
get Offect Minutes
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
int m1 = calendar1.get(Calendar.MINUTE);
int m2 = calendar2.get(Calendar.MINUTE);
int h = getOffectHour(date1, date2);
int m = 0;
...
intgetOffectMinutes(long date1, long date2)
get Offect Minutes
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
int m1 = calendar1.get(Calendar.MINUTE);
int m2 = calendar2.get(Calendar.MINUTE);
int h = getOffectHour(date1, date2);
int m = 0;
...
StringgetStringByOffset(Date date, String format, int calendarField, int offset)
get String By Offset
String strDate = null;
try {
    Calendar c = new GregorianCalendar();
    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(
            format);
    c.setTime(date);
    c.add(calendarField, offset);
    strDate = mSimpleDateFormat.format(c.getTime());
...
StringgetStringByOffset(Date date, String format, int calendarField, int offset)
get String By Offset
String strDate = null;
try {
    Calendar c = new GregorianCalendar();
    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(
            format);
    c.setTime(date);
    c.add(calendarField, offset);
    strDate = mSimpleDateFormat.format(c.getTime());
...
StringgetStringByOffset(String strDate, String format, int calendarField, int offset)
get String By Offset
String mDateTime = null;
try {
    Calendar c = new GregorianCalendar();
    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(
            format);
    c.setTime(mSimpleDateFormat.parse(strDate));
    c.add(calendarField, offset);
    mDateTime = mSimpleDateFormat.format(c.getTime());
...
StringgetStringByOffset(String strDate, String format, int calendarField, int offset)
get String By Offset
String mDateTime = null;
try {
    Calendar c = new GregorianCalendar();
    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(
            format);
    c.setTime(mSimpleDateFormat.parse(strDate));
    c.add(calendarField, offset);
    mDateTime = mSimpleDateFormat.format(c.getTime());
...
intgetDaysSince(Date date)
get Days Since
if (date == null) {
    return 0;
return (int) ((getCurrentEpochTime() - date.getTime()) / ONE_DAY_IN_MILLIS);
StringtimeAgo(Date d)
time Ago
final long referenceTime = d.getTime();
final long nowTime = System.currentTimeMillis();
final long diffTime = Math.abs(nowTime - referenceTime);
if (diffTime > DateUtils.DAY_IN_MILLIS) {
    return format(d, "yyyy-MM-dd HH:mm");
} else if (diffTime > DateUtils.HOUR_IN_MILLIS) {
    return String.format(TIMEAGO_HOURS_AGO, diffTime
            / DateUtils.HOUR_IN_MILLIS);
...