Android Long to Date Convert getUTCandRelativeDateFromElapsedTime( long elapsedTime)

Here you can find the source of getUTCandRelativeDateFromElapsedTime( long elapsedTime)

Description

get UT Cand Relative Date From Elapsed Time

Declaration

public static String getUTCandRelativeDateFromElapsedTime(
            long elapsedTime) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

import android.os.SystemClock;

public class Main {
    private final static SimpleDateFormat formatter = new SimpleDateFormat(
            "dd/HH:mm:ss");

    public static String getUTCandRelativeDateFromElapsedTime(
            long elapsedTime) {
        try {// w  w  w . ja  v a2  s  .  c om
            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) {
                sb.append('{');
                sb.append(android.text.format.DateUtils
                        .getRelativeTimeSpanString(
                                time,
                                curTime,
                                android.text.format.DateUtils.MINUTE_IN_MILLIS,
                                flags).toString());
                sb.append('}');
            }
            return sb.toString();
        } catch (java.lang.Throwable th) {
            return "TIME_ERROR";
        }
    }
}

Related

  1. getTimeLabel(long time)
  2. getTimestampDatetime(long milliseconds)
  3. getUTCTimeFromElapsedTime(long elapsedTime)
  4. getUTCTimeFromLocalMillis(long localMillis)
  5. getUTCandRelativeDateFromElapsedTime( long elapsedTime)
  6. getUniversalDateStamp(long time)
  7. getUpdateDateStr(long time)
  8. getUpdateTimeStr(long time)
  9. getYear(long dateTimeMillis)