判断是不是同一天,同一周
2014-04-29 18:47
381 查看
public static boolean sameDay(Date d0,Date d2){ if(null == d0 || null == d2){ return false ; } Calendar c0 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c0.setTime(d0); c2.setTime(d2); if(c0.get(Calendar.YEAR) != c2.get(Calendar.YEAR)){ return false; } if(c0.get(Calendar.MONTH) != c2.get(Calendar.MONTH)){ return false; } if(c0.get(Calendar.DATE) != c2.get(Calendar.DATE)){ return false; } return true; } public static boolean isSameWeek(Date d0, Date d1) { Calendar c0 = Calendar.getInstance(); Calendar c1 = Calendar.getInstance(); c0.setTime(d0); c1.setTime(d1); int subYear = c0.get(Calendar.YEAR) - c1.get(Calendar.YEAR); if (0 == subYear) { if (c0.get(Calendar.WEEK_OF_YEAR) == c1.get(Calendar.WEEK_OF_YEAR)) return true; } else if (1 == subYear && 11 == c1.get(Calendar.MONTH)) { if (c0.get(Calendar.WEEK_OF_YEAR) == c1.get(Calendar.WEEK_OF_YEAR)) return true; } else if (-1 == subYear && 11 == c0.get(Calendar.MONTH)) { if (c0.get(Calendar.WEEK_OF_YEAR) == c1 .get(Calendar.WEEK_OF_YEAR)) return true; } return false; }
相关文章推荐
- 设计模式(16) 观察者模式(OBSERVER)C++实现
- 用NSSetUncaughtExceptionHandler捕获程序异常
- 解决maven传递依赖中的版本冲突
- map 按key排序 按value排序
- 优化的NSLog技巧
- Hadoop(HDFS、YARN、HBase、Hive和Spark等)默认端口表
- maven 建立本地仓库
- Executor框架管理线程
- delphi Form属性设置 设置可实现窗体无最大化,并且不能拖大拖小
- 指针 new delete
- 简单的Samba服务器安装
- ecshop商品详细页显示已售商品数量和评论数量
- iperf测试UDP带宽
- Struts2 Tomcat class.classLoader.resources.dirContext.docBase赋值造成的DoS及远程代码执行利用!
- 高级语言类型划分
- 学习poi在java上的运用
- Centos安装Zabbix
- UVALive 6577 Binary Tree 二叉树的LRU串
- 究竟是测试重要,还是工程重要?
- jquery post方法在servlet中的使用方法