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

StringgetTimeLabel(long time)
Returns label for the time.
return formatter.format(new Date(time));
StringgetTimestampDatetime(long milliseconds)
get Timestamp Datetime
Date date = new Date(milliseconds);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
StringgetUTCTimeFromElapsedTime(long elapsedTime)
get UTC Time From Elapsed Time
return formatter.format(new Date(System.currentTimeMillis()
        - (SystemClock.elapsedRealtime() - elapsedTime)));
longgetUTCTimeFromLocalMillis(long localMillis)
Convert a local timestamp into UTC time
return localMillis + getTimeZoneOffsetInMillis();
StringgetUTCandRelativeDateFromElapsedTime( long elapsedTime)
get UT Cand Relative Date From Elapsed Time
try {
    SimpleDateFormat formatter = new SimpleDateFormat("dd/HH:mm:ss");
    int flags = android.text.format.DateUtils.FORMAT_ABBREV_RELATIVE;
    long curTime = System.currentTimeMillis();
    long time = curTime
            - (SystemClock.elapsedRealtime() - elapsedTime);
    StringBuffer sb = new StringBuffer();
    sb.append(formatter.format(new Date(time)));
...
StringgetUTCandRelativeDateFromElapsedTime( long elapsedTime)
get UT Cand Relative Date From Elapsed Time
try {
    int flags = android.text.format.DateUtils.FORMAT_ABBREV_RELATIVE;
    long curTime = System.currentTimeMillis();
    long time = curTime
            - (SystemClock.elapsedRealtime() - elapsedTime);
    StringBuffer sb = new StringBuffer();
    sb.append(formatter.format(new Date(time)));
    if (time <= curTime) {
...
StringgetUniversalDateStamp(long time)
Get current time stamp in universal format
Format: yyyy-mm-ddThh:mm:ssZ
e.g.: 1999-09-09T13:10:40Z
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(time));
return getUniversalDateStamp(cal);
StringgetUpdateDateStr(long time)
get Update Date Str
SimpleDateFormat dateFormat = new SimpleDateFormat(
        UPDATE_TIME_FORMAT);
Date d = new Date(time);
return dateFormat.format(d);
StringgetUpdateTimeStr(long time)
get Update Time Str
SimpleDateFormat dateFormat = new SimpleDateFormat(
        UPDATE_TIME_STR_FORMAT);
Date d = new Date(time);
return dateFormat.format(d);
intgetYear(long dateTimeMillis)
get Year
SimpleDateFormat format = new SimpleDateFormat("yyyy");
StringBuilder dateString = new StringBuilder(
        format.format(dateTimeMillis));
return Integer.parseInt(dateString.toString());