Android Day Get getSmartDateString(long time, String extString, String zeroDayString)

Here you can find the source of getSmartDateString(long time, String extString, String zeroDayString)

Description

get Smart Date String

Declaration

public static String getSmartDateString(long time, String extString,
            String zeroDayString) 

Method Source Code

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;
    }
}

Related

  1. firstDay(Date date)
  2. getDay(long dateTimeMillis)
  3. getDaySelect(String selectName, String value, boolean hasBlank)
  4. getDaySelect(String selectName, String value, boolean hasBlank, String js)
  5. getCurrentDay()
  6. getWeatherDateStr(int day)
  7. getArrayDiffDays(String startDate, String endDate)
  8. getIndexDay(Date origin, int index)
  9. getDateOfLastSunday(Date d)