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

StringgetRelativeDateLabel(long time)
get Relative Date Label
long curTime = System.currentTimeMillis();
long startTimeOfToday = getStartTimeOfDay(curTime);
if (time > curTime) {
    return getDateLabel(time);
} else if (time > startTimeOfToday) {
    return getTimeLabel(time);
} else {
    return getDateLabel(time);
...
StringgetRelativeTimeFromMilliSeconds(long dateInMillis)
get Relative Time From Milli Seconds
final String relativeTime = DateUtils.getRelativeTimeSpanString(
        dateInMillis, System.currentTimeMillis(),
        DateUtils.SECOND_IN_MILLIS).toString();
return formatRelativeTime(relativeTime);
StringgetShortDateString(long date, Locale locale)
get Short Date String
return getDateString(date, DateFormat.SHORT, locale);
StringgetShortDateTimeString(long date, Locale locale)
get Short Date Time String
return getDateTimeString(new Date(date), DateFormat.SHORT, locale);
StringgetSimpleDatetime(long milliseconds)
get Simple Datetime
Date date = new Date(milliseconds);
DateFormat sdf = SimpleDateFormat.getDateTimeInstance();
return sdf.format(date);
StringgetStandardTime(long timestamp)
get Standard Time, "MM/dd/HH:mm"
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/HH:mm");
Date date = new Date(timestamp * 1000);
sdf.format(date);
return sdf.format(date);
longgetStartTimeOfDay(long timeInLong)
get Start Time Of Day
Time time = new Time();
time.set(timeInLong);
Time dayStartTime = new Time();
dayStartTime.year = time.year;
dayStartTime.month = time.month;
dayStartTime.monthDay = time.monthDay;
return dayStartTime.toMillis(true);
StringgetStringOfLong(long date)
get String Of Long
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
today = sdf.format(date);
return today;
StringgetTimeInterval(long interval)
get Time Interval
if (interval <= 0) {
    return "00:00:00";
long intervalSeconds = interval / 1000;
long hours = intervalSeconds / 3600;
long minutes = (intervalSeconds % 3600) / 60;
long seconds = intervalSeconds % 60;
String hoursText = String.valueOf(hours);
...
StringgetTimeLabel(long date)
get Time Label
SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT);
return sdf.format(date);