不好意思,标题党了一下~~~~
我的问题是这样的,我昨天没说清楚。这样啊,我来把大框架说一说,大家一起来填空哈
我的目标是写一个java日期处理类,就像新浪微博那样的。功能是实现两个方法,一个是我在保存条目的时候要记录
一下当前的时间,不管什么格式都行,因为只是记录,不是显示。另一个方法是我在要显示时间的时候把原来存进去的时间
拿进来转化一下,更当前时间比较一下,如果是同年,就不显示年份,如果是同月,就不显示月份,如果是当天就显示今天,
如果是昨天就显示昨天,如果是半个小时以前,就显示 xx分钟以前,其他的就显示 xx年xx月xx日 HH:MM:SS 。
下面是部分代码:public class DateHandler {
public String getNewDate(){//这里不一定返回String
//........
return //返回一个用于记录的当前时间,别的方法调用就能的到此数据,任何格式都行,只是用于记录储存。
}
public String handelDate(//传进来原来储存的数据 aa){
//这里再获得一个当前的日期 bb,
//这里做比较,如果 aa的年份与 bb 相同,去掉年份,月份相同去掉月份,如果是当天就显示今天,
//如果是昨天就显示昨天,如果是半个小时以前,就显示 xx分钟以前,其他的就显示 xx年xx月xx日 HH:MM:SS 。
return //返回处理过后的字符串。用于前台显示。
}
}
基本上我就这么个意思,想要实现这么个东东,但是我对各种数据类型,尤其是date类的,特别不是很懂,不知道歌会总数据的转化和处理,所以,像求求大神们,能不能集思广益一下,小弟就当是学习。
祝有心的大神中秋遇美女,国庆中大奖,各种好人有好报。
我的问题是这样的,我昨天没说清楚。这样啊,我来把大框架说一说,大家一起来填空哈
我的目标是写一个java日期处理类,就像新浪微博那样的。功能是实现两个方法,一个是我在保存条目的时候要记录
一下当前的时间,不管什么格式都行,因为只是记录,不是显示。另一个方法是我在要显示时间的时候把原来存进去的时间
拿进来转化一下,更当前时间比较一下,如果是同年,就不显示年份,如果是同月,就不显示月份,如果是当天就显示今天,
如果是昨天就显示昨天,如果是半个小时以前,就显示 xx分钟以前,其他的就显示 xx年xx月xx日 HH:MM:SS 。
下面是部分代码:public class DateHandler {
public String getNewDate(){//这里不一定返回String
//........
return //返回一个用于记录的当前时间,别的方法调用就能的到此数据,任何格式都行,只是用于记录储存。
}
public String handelDate(//传进来原来储存的数据 aa){
//这里再获得一个当前的日期 bb,
//这里做比较,如果 aa的年份与 bb 相同,去掉年份,月份相同去掉月份,如果是当天就显示今天,
//如果是昨天就显示昨天,如果是半个小时以前,就显示 xx分钟以前,其他的就显示 xx年xx月xx日 HH:MM:SS 。
return //返回处理过后的字符串。用于前台显示。
}
}
基本上我就这么个意思,想要实现这么个东东,但是我对各种数据类型,尤其是date类的,特别不是很懂,不知道歌会总数据的转化和处理,所以,像求求大神们,能不能集思广益一下,小弟就当是学习。
祝有心的大神中秋遇美女,国庆中大奖,各种好人有好报。
解决方案 »
- 腾讯空间里面那个上传相片的控件是什么呢
- 如何遍历一个实体类的所有get方法
- ==>> 为什么网站象死了一样?
- 一个简单的问题
- 200分求一server push例子代码。
- 请问我想用JAVASCRIPT中的window.open(myAction.do)这样的方法来调用STRUTS中定义的ACTION,可以这样用吗
- 用什么方法知道某个网叶所在网站的虚拟目录的本地文件夹路径?
- 我的jsp服务器是iis+TOMCAT+win2000pro 不知怎的每次用不了多久就显示出 网页无法显示 目前访问该 Web 站点的用户过多,我只是自已用怎么
- JSP参数传递的问题
- 用什么工具编写JSP,可以象用InterDev编写ASP一样方便快捷?
- checkbox 默认选中问题,求高手,在线等
- 急!如何让鼠标移动到一个超链接以后字体变红?
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;
}
}