Here you can find the source of getRelativeDateLabel(long time)
public static String getRelativeDateLabel(long time)
//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); } }