Android Utililty Methods Long to Date Convert

List of utility methods to do Long to Date Convert

Description

The list of methods to do Long to Date Convert are organized into topic(s).

Method

StringstringForTime(long timeMs)
string For Time
long totalSeconds = timeMs / 1000;
long seconds = totalSeconds % 60;
long minutes = (totalSeconds / 60) % 60;
long hours = totalSeconds / 3600;
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
StringgetTimeString(long millis)
get Time String
StringBuffer buffer = new StringBuffer();
int minutes = (int) ((millis % (1000 * 60 * 60)) / (1000 * 60));
int seconds = (int) (((millis % (1000 * 60 * 60)) % (1000 * 60)) / 1000);
buffer.append(String.format("%02d", minutes)).append(":")
        .append(String.format("%02d", seconds));
return buffer.toString();
StringparseTime(long time, String pattern)
parse Time
Date date = new Date(time);
if (isBlank(pattern)) {
    pattern = "yyyy-MM-dd HH:mm";
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern,
        Locale.getDefault());
return dateFormat.format(date);
DategetDateByInt(long va)
get Date By Int
Date result = new Date();
result.setTime(va);
return result;
StringgetDateTimeString(long dateTime)
get Date Time String
SimpleDateFormat format = new SimpleDateFormat("HH:mm dd/MM/yy");
StringBuilder dateString = new StringBuilder(
        format.format(dateTime));
return dateString.toString();
StringgetLabelForEventInTime(long inTime)
Returns a label for event happened inTime ms
return android.text.format.DateUtils.getRelativeTimeSpanString(
        inTime, 0, 0)
        + " at "
        + getTimeLabel(inTime + System.currentTimeMillis());
StringgetTimeDelta(long delta, String dateFormat)
Returns time delta from current time with `dateFormat`
Calendar current = Calendar.getInstance();
current.setTimeInMillis(current.getTimeInMillis() + delta);
return formatDate(current.getTime(), dateFormat);
TimeContainertimeAgo(long aTime)
time Ago
TimeContainer result = null;
long currentTime = System.currentTimeMillis();
long delta = currentTime - aTime;
if (delta > 0) {
    result = new TimeContainer();
    if (delta / (1000 * 60 * 60 * 24 * 30 * 12) > 0) {
        result.count = (int) (delta / (1000 * 60 * 60 * 24 * 30 * 12));
        result.time = Time.YEAR;
...
booleanisTomorrow(long lTime)
is Tomorrow
return isDateDayEqual(lTime, getTimeNextDay(lTime));
StringgetActivityTime(long startTime, long endTime)
get Activity Time
long differenceInSeconds = endTime - startTime;
if (differenceInSeconds < 60) {
    return differenceInSeconds + "sec";
} else {
    long minutes = differenceInSeconds / 60;
    if (minutes < 60) {
        return minutes + "min";
    } else {
...