2008-03-01
判断给定日期是否为当天
关键字: date
此函数可以用于实现对按时间排序的记录进行归类,比如:可以区分当天的记录,一周之内的记录和更早的记录。现在好多邮件系统都实现了此功能。
/**
* 判断给定日期是否为当天,
*距离当前时间七天之内的日期,和七天之外的日期
* @param dt
* @param type 0--当天 1--7天之内的 2--7天之外的
* @return
*/
public static boolean getDayDiffFromToday(Date dt,int type){
Date today=new Date();
today.setHours(23);
today.setMinutes(59);
today.setSeconds(59);
long diff = today.getTime() - dt.getTime();
if(diff<0)diff=0;
long days = diff/(1000*60*60*24);
if(type==0 && days==0)return true;
if(type==1 && days>0 && days<=7)return true;
if(type==2 && days>7)return true;
return false;
}
/**
* 判断给定日期是否为当天,
*距离当前时间七天之内的日期,和七天之外的日期
* @param dt
* @param type 0--当天 1--7天之内的 2--7天之外的
* @return
*/
public static boolean getDayDiffFromToday(Date dt,int type){
Date today=new Date();
today.setHours(23);
today.setMinutes(59);
today.setSeconds(59);
long diff = today.getTime() - dt.getTime();
if(diff<0)diff=0;
long days = diff/(1000*60*60*24);
if(type==0 && days==0)return true;
if(type==1 && days>0 && days<=7)return true;
if(type==2 && days>7)return true;
return false;
}
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 1748 次
- 性别:

- 来自: 大连

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
MyEclipse的UML设计支持
这样的教程不明了,最好用视频.我觉得myeclipse uml还是比较简单的,只 ...
-- by pdw2009 -
java正则表达式
是好贴,不过里面的错误有点多啊。
-- by yoyokaka -
linux AS4+apache+tomcat ...
mod_proxy_ajp 才是正解,不要走弯路了!
-- by crofton -
linux AS4+apache+tomcat ...
http://tomcat.apache.org/connectors-doc/ ...
-- by pupi -
linux AS4+apache+tomcat ...
mod_jk已经被淘汰了,改用mod_proxy_ajp吧。
-- by robbin






评论排行榜