Android Long to Date Convert getRelativeDateLabel(long time)

Here you can find the source of getRelativeDateLabel(long time)

Description

get Relative Date Label

License

Open Source License

Declaration

public static String getRelativeDateLabel(long time) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import android.text.format.Time;

public class Main {
    private static String TIME_FORMAT = "HH:mm";
    private static String DATE_FORMAT = "yyyy-MM-dd";

    public static String getRelativeDateLabel(long time) {
        long curTime = System.currentTimeMillis();
        long startTimeOfToday = getStartTimeOfDay(curTime);

        if (time > curTime) {
            return getDateLabel(time);
        } else if (time > startTimeOfToday) {
            return getTimeLabel(time);
        } else {//  ww w. j  a  v a2 s.c  o  m
            return getDateLabel(time);
        }

    }

    public static long getStartTimeOfDay(long timeInLong) {
        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);
    }

    public static String getDateLabel(long date) {
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        return sdf.format(date);
    }

    public static String getTimeLabel(long date) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT);
        return sdf.format(date);
    }
}

Related

  1. getNameForDcim(long time)
  2. getNameForFile(long time)
  3. getNumberOfDaysPassed(long date1, long date2)
  4. getReadableTimeStamp(long timeStamp)
  5. getReadableTimeUsage(long timeUsageMs)
  6. getRelativeTimeFromMilliSeconds(long dateInMillis)
  7. getShortDateString(long date, Locale locale)
  8. getShortDateTimeString(long date, Locale locale)
  9. getSimpleDatetime(long milliseconds)