/**
* 将时间 换为人性化的时间
* 01-05 17:43
* @param date
* @return
*/
public static String makeLovelyDate(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat(PATTEN_YEAR_MM_DD);
String timePattern = " HH:mm";
String weekPattern = "E";
String dateString;
long timeMinus = 0L;
timeMinus = (date.getTime()) - System.currentTimeMillis() ;
int n = new Double(Math.floor(timeMinus / 24D/3600/1000)).intValue();
if(n == -1)
{
dateString = "昨天" ;
}else if(n == 0)
{
dateString = "今天";
}else if(n == 1)
{
dateString = "明天";
}else if(n >= 2 && n <= 5)
{
dateString = FastDateFormat.getInstance(weekPattern, Locale.CHINESE).format(date);
}else
{
dateString = sdf.format(date);
}
dateString = dateString + FastDateFormat.getInstance(timePattern).format(date);
return dateString;
}
/**
* 日期转为昨天,今天,明天
*/
public static String convertDate(Date date){
Calendar today = Calendar.getInstance();
Calendar old = Calendar.getInstance();
old.setTime(date);
today.set(Calendar.HOUR, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
old.set(Calendar.HOUR, 0);
old.set(Calendar.MINUTE, 0);
old.set(Calendar.SECOND, 0);
//老的时间减去今天的时间
long intervalMilli = old.getTimeInMillis() - today.getTimeInMillis();
int xcts = (int) (intervalMilli / (24 * 60 * 60 * 1000));
// -2:前天 -1:昨天 0:今天 1:明天 2:后天, out:显示日期
if (xcts == -2) {
return "前天";
} else if (xcts == -1) {
return "昨天";
} else if (xcts == 0) {
return "今天";
} else if (xcts == 1) {
return "明天";
}else if (xcts == 2) {
return "后天";
}else{
return "====";
}
}