public static String formatShort(Date date) {
Date now = new Date();
long time = now.getTime() - date.getTime();
if (time < 60 * 60 * 1000) {
return (time / 1000 / 60) + "分钟前";
} else if (time < 24 * 60 * 60 * 1000) {
return (time / 1000 / 60 / 60) + "小时前";
} else {
return (time / 1000 / 60 / 60 / 24) + "天前";
}
}
/**
* 将得到当前时间 格式 “2011年8月15日 星期一”
*
* @return
*/
public static String getTimeString() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
return String.format("%s年%s月%s日 %s", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH), dayOfWeek(calendar));
}
public static String dayOfWeek(Calendar calendar){
final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五","星期六" };
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)-1;
if(dayOfWeek <0)dayOfWeek=0;
return dayNames[dayOfWeek];
}