/**
* 判断时间
*
* @param time
* @return
*/
public static String formatDateTime(long time) {
//
// SimpleDateFormat format = new java.text.SimpleDateFormat(
// "yyyy-MM-dd HH:mm");
if (time == 0 || "".equals(time)) {
return "";
}
Date date = null;
date= new Date(1000*time); //转换为妙
SimpleDateFormat format = new java.text.SimpleDateFormat(
"yyyy-MM-dd HH:mm");
String datetime = format.format(date); //时间的 字符串
// try {
// date = format.parse(time);
// } catch (ParseException e) {
// e.printStackTrace();
// } catch (java.text.ParseException e) {
//
// e.printStackTrace();
// }
Calendar current = Calendar.getInstance();
Calendar today = Calendar.getInstance(); // 今天
today.set(Calendar.YEAR, current.get(Calendar.YEAR));
today.set(Calendar.MONTH, current.get(Calendar.MONTH));
today.set(Calendar.DAY_OF_MONTH, current.get(Calendar.DAY_OF_MONTH));
// Calendar.HOUR——12小时制的小时数 Calendar.HOUR_OF_DAY——24小时制的小时数
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
Calendar yesterday = Calendar.getInstance(); // 昨天
yesterday.set(Calendar.YEAR, current.get(Calendar.YEAR));
yesterday.set(Calendar.MONTH, current.get(Calendar.MONTH));
yesterday.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH) - 1);
yesterday.set(Calendar.HOUR_OF_DAY, 0);
yesterday.set(Calendar.MINUTE, 0);
yesterday.set(Calendar.SECOND, 0);
Calendar mintianday = Calendar.getInstance(); // 明天
mintianday.set(Calendar.YEAR, current.get(Calendar.YEAR));
mintianday.set(Calendar.MONTH, current.get(Calendar.MONTH));
mintianday.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH) +1);
mintianday.set(Calendar.HOUR_OF_DAY, 0);
mintianday.set(Calendar.MINUTE, 0);
mintianday.set(Calendar.SECOND, 0);
Calendar houtianday = Calendar.getInstance(); // 后天
houtianday.set(Calendar.YEAR, current.get(Calendar.YEAR));
houtianday.set(Calendar.MONTH, current.get(Calendar.MONTH));
houtianday.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH) + 2);
houtianday.set(Calendar.HOUR_OF_DAY, 0);
houtianday.set(Calendar.MINUTE, 0);
houtianday.set(Calendar.SECOND, 0);
Calendar dahoutianday = Calendar.getInstance(); // da后天
dahoutianday.set(Calendar.YEAR, current.get(Calendar.YEAR));
dahoutianday.set(Calendar.MONTH, current.get(Calendar.MONTH));
dahoutianday.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH) + 3);
dahoutianday.set(Calendar.HOUR_OF_DAY, 0);
dahoutianday.set(Calendar.MINUTE, 0);
dahoutianday.set(Calendar.SECOND, 0);
current.setTime(date);
if (current.after(today)&& current.before(mintianday)) {
return "今天 " + datetime.split(" ")[1];
} else if (current.before(today) && current.after(yesterday)) {
return "昨天 " + datetime.split(" ")[1];
} else if (current.after(mintianday) && current.before(houtianday)) {
return "明天 " + datetime.split(" ")[1];
} else if (current.after(houtianday) && current.before(dahoutianday)) {
return "后天 " + datetime.split(" ")[1];
}else {
int index = datetime.indexOf("-") + 1;
return datetime.substring(index, datetime.length());
}
}
// 判断 两个时间 ,相差 几天 几小时 ,几分
public static boolean isYuyue(long deliverydate ){
deliverydate=deliverydate*1000;
Date nows= new java.util.Date();
long nowTime = nows.getTime();
long cha = deliverydate-nowTime;
Long day = (cha)/86400000;
Long hour = ((cha)%86400000)/3600000;
Long min = ((cha)%86400000%3600000)/60000;
if(day>0){
return true;
}else {
if(hour>0){
return true;
}else { //day
return false; //立即配送
}
}
}