日期:2014-05-17 浏览次数:20955 次
public class DateHandler {
public String getNewDate(){//这里不一定返回String
//........
return //返回一个用于记录的当前时间,别的方法调用就能的到此数据,任何格式都行,只是用于记录储存。
}
public String handelDate(//传进来原来储存的数据 aa){
//这里再获得一个当前的日期 bb,
//这里做比较,如果 aa的年份与 bb 相同,去掉年份,月份相同去掉月份,如果是当天就显示今天,
//如果是昨天就显示昨天,如果是半个小时以前,就显示 xx分钟以前,其他的就显示 xx年xx月xx日 HH:MM:SS 。
return //返回处理过后的字符串。用于前台显示。
}
}
public class DateManage {
public String getCurrentDate(){
Date date = new Date();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sf.format(date);
}
public String manageDate(String arg_date){
String return_str = null;
Date current_time = new Date();
DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date arg_time = null;
try {
arg_time = df.parse(arg_date);
} catch (ParseException e) {
e.printStackTrace();
}
if(current_time.getYear() == arg_time.getYear()) {
SimpleDateFormat delyear = new SimpleDateFormat("MM月dd日 HH:mm:ss");
return_str = delyear.format(arg_time);
if(current_time.getMonth() == arg_time.getMonth()) {
SimpleDateFormat delmonth = new SimpleDateFormat("dd日 HH:mm:ss");
return_str = delmonth.format(arg_time);
if(current_time.getDate() == arg_time.getDate()) {
SimpleDateFormat deldate = new SimpleDateFormat("HH:mm:ss");
return_str = "今天 " + deldate.format(arg_time);
if(current_time.getHours() == arg_time.getHours() && 30 > current_time.getMinutes()-arg_time.getMinutes()) {
return_str = current_time.getMinutes()-arg_time.getMinutes() + "分钟前";
if(0 == current_time.getMinutes()-arg_time.getMinutes()) {
return_str = current_time.getSeconds()-arg_time.getSeconds() + "秒前";
}
}
} else if(1 == current_time.getDate() - arg_time.getDate()) {
SimpleDateFormat deldate = new SimpleDateFormat("HH:mm:ss");
return_str = "昨天 " + deldate.format(arg_time);
}
}
} else {
SimpleDateFormat alldate = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
return_str = alldate.format(arg_time);
}
return return_str;