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));
        }
    
    }
  • 相关阅读:
    文件拖放
    有关函数传参的结构赋值的理解
    js_点击弹出图片
    js 比较网址与a链接
    css——鼠标经过按钮时样式(radial-gradient)
    文字跳动
    kafka 数据存储和发送
    kafka 消息存储分析
    Kafka 内存管理类BufferPool
    聊聊kafka-client的源码
  • 原文地址:https://www.cnblogs.com/blackmlik/p/12067398.html
Copyright © 2011-2022 走看看