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));
        }
    
    }
  • 相关阅读:
    Java低配版简单的随机点名系统
    是否二叉搜索树
    输出学生成绩
    求给定精度的简单交错序列部分和
    字符串的连接
    学生信息链表,建立,插入,删除,遍历,查找,修改,最大(小)值,平均
    测试文档(final)
    详细设计文档(final)
    概要设计文档(final)
    需求规格说明书(final)
  • 原文地址:https://www.cnblogs.com/blackmlik/p/12067398.html
Copyright © 2011-2022 走看看