Here you can find the source of getSmartDateString(long time, String extString, String zeroDayString)
public static String getSmartDateString(long time, String extString, String zeroDayString)
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main{ public static long oneDay = 1000 * 60 * 60 * 24; public static String getSmartDateString(long time, String extString, String zeroDayString) { long theTime = getDayStartTime(time); long nowTime = getDayStartTime(System.currentTimeMillis()); long moreTime = nowTime - theTime; if (moreTime <= 0L) { return zeroDayString; }/*from w ww. j ava 2s . c o m*/ if (moreTime < oneDay * 7) { return (moreTime / oneDay) + " " + extString; } else { return sf.format(getDateByInt(time)); } } public static long getDayStartTime(long time) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); String strDay = sf.format(cal.getTime()); long result; try { result = sf.parse(strDay).getTime(); } catch (ParseException e) { result = time; } return result; } public static Date getDateByInt(long va) { Date result = new Date(); result.setTime(va); return result; } }