Android Long to Date Convert timeAgo(long aTime)

Here you can find the source of timeAgo(long aTime)

Description

time Ago

License

Apache License

Declaration

public static TimeContainer timeAgo(long aTime) 

Method Source Code

//License from project: Apache License 

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main{
    public static TimeContainer timeAgo(long aTime) {
        TimeContainer result = null;//from   w  ww  .j  a  v a2 s.  c  om
        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;
            } else if (result.count == 0
                    && delta / (1000 * 60 * 60 * 24 * 30) > 0) {
                result.count = (int) (delta / (1000 * 60 * 60 * 24 * 30));
                result.time = Time.MONTH;
            } else if (result.count == 0
                    && delta / (1000 * 60 * 60 * 24) > 0) {
                result.count = (int) (delta / (1000 * 60 * 60 * 24));
                result.time = Time.DAY;
            } else if (result.count == 0 && delta / (1000 * 60 * 60) > 0) {
                result.count = (int) (delta / (1000 * 60 * 60));
                result.time = Time.HOUR;
            } else if (result.count == 0 && delta / (1000 * 60) > 0) {
                result.count = (int) (delta / (1000 * 60));
                result.time = Time.MIN;
            } else if (result.count == 0 && delta / (1000) > 0) {
                result.count = (int) (delta / 1000);
                result.time = Time.SEC;
            }
        }
        return result;
    }
}

Related

  1. parseTime(long time, String pattern)
  2. getDateByInt(long va)
  3. getDateTimeString(long dateTime)
  4. getLabelForEventInTime(long inTime)
  5. getTimeDelta(long delta, String dateFormat)
  6. isTomorrow(long lTime)
  7. getActivityTime(long startTime, long endTime)
  8. getDate(long timeStamp)
  9. getDateFrom(long timestamp, Context context)