zoukankan      html  css  js  c++  java
  • 判断是否同一天 同一月

    package untils;
    
    import java.util.Calendar;
    import java.util.Date;
    
    public class DateUtils {
        public static boolean isSameMonth(Date date1, Date date2) {
            if (date1 == null || date2 == null) {
                throw new IllegalArgumentException("The date must not be null");
            }
            Calendar cal1 = Calendar.getInstance();
            cal1.setTime(date1);
            Calendar cal2 = Calendar.getInstance();
            cal2.setTime(date2);
            return isSameMonth(cal1, cal2);
        }
        public static boolean isSameMonth(Calendar cal1, Calendar cal2) {
            if (cal1 == null || cal2 == null) {
                throw new IllegalArgumentException("The date must not be null");
            }
            return (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
                    cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH));
        }
       public static boolean isSameDay(Date date1, Date date2) {
            if (date1 == null || date2 == null) {
                throw new IllegalArgumentException("The date must not be null");
            }
            Calendar cal1 = Calendar.getInstance();
            cal1.setTime(date1);
            Calendar cal2 = Calendar.getInstance();
            cal2.setTime(date2);
            return isSameDay(cal1, cal2);
        }
      public static boolean isSameDay(Calendar cal1, Calendar cal2) {
            if (cal1 == null || cal2 == null) {
                throw new IllegalArgumentException("The date must not be null");
            }
            return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
                    cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
                    cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
        }
    
    }
  • 相关阅读:
    UIAction 公共界面访问控制(拦截控制)
    MD5加密
    SVN的简单用法
    Spring AOP基础之JDK动态代理
    Spring中的事务管理模块基础
    Spring添加Junit4支持
    Spring里面dbcp连接池的配置和使用
    vue.js自定义指令详解
    vue input输入框联想
    export ,export default 和 import 区别 以及用法
  • 原文地址:https://www.cnblogs.com/blackmlik/p/12067398.html
Copyright © 2011-2022 走看看