app/src/main/java/id/rainey/master/utils/LDateFormat.java
// Get time range from today to a past date
Get time range from today to a past date
Get time range from today to a past date
public static String timeRangeUntilToday(String pastDate) {
        Date d1 = getDateObject(pastDate, "yyyy-MM-dd HH:mm:ss");
        Date d2 = getDateObject(currentDateAndTime(), "yyyy-MM-dd HH:mm:ss");
        long diff = d2.getTime() - d1.getTime();
        long diffSeconds = diff / 1000 % 60;
        long diffMinutes = diff / (60 * 1000) % 60;
        long diffHours = diff / (60 * 60 * 1000) % 24;
        long diffDays = diff / (24 * 60 * 60 * 1000) % 7;
        long diffWeeks = diff / (7 * 24 * 60 * 60 * 1000);
        if (diffWeeks > 0) return diffWeeks + "w";
        else if (diffDays > 0) return diffDays + "d";
        else if (diffHours > 0) return diffHours + "h";
        else if (diffMinutes > 0) return diffMinutes + "m";
        else return (diffSeconds < 10) ? "Just now" : diffSeconds + "s";
    }
public static String timeRangeUntilToday ( String pastDate ) { Date d1 = getDateObject ( pastDate , "yyyy-MM-dd HH:mm:ss" ) ; Date d2 = getDateObject ( currentDateAndTime ( ) , "yyyy-MM-dd HH:mm:ss" ) ; long diff = d2 . getTime ( ) - d1 . getTime ( ) ; long diffSeconds = diff / 1000 % 60 ; long diffMinutes = diff / ( 60 * 1000 ) % 60 ; long diffHours = diff / ( 60 * 60 * 1000 ) % 24 ; long diffDays = diff / ( 24 * 60 * 60 * 1000 ) % 7 ; long diffWeeks = diff / ( 7 * 24 * 60 * 60 * 1000 ) ; if ( diffWeeks > 0 ) return diffWeeks + "w" ; else if ( diffDays > 0 ) return diffDays + "d" ; else if ( diffHours > 0 ) return diffHours + "h" ; else if ( diffMinutes > 0 ) return diffMinutes + "m" ; else return ( diffSeconds < 10 ) ? "Just now" : diffSeconds + "s" ; }
Get time range from today to a past date
Get time range from today to a past date
//in milliseconds