zoukankan      html  css  js  c++  java
  • java日期大小比较

      //直接用Date自带方法before()和after()比较
        public static void main(String[] args) throws ParseException {
             String beginTime=new String("2017-05-08 11:22:22");    
             String zhongjianTime=new String("2017-06-08 10:22:22");
             String endTime=new String("2017-06-09 10:22:22");
             SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

              Date sd1=df.parse(beginTime);
              Date zhongjian=df.parse(zhongjianTime);
              Date sd2=df.parse(endTime);

              System.out.println(sd1.before(sd2));
              System.out.println(sd1.after(sd2))
              System.out.println(sd1.before(zhongjian) && zhongjian.before(sd2));  
        }

      //结果为:
      true     false    true

    SimpleDateFormat sb=new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //转为data类型的时间 登记时间的开始 和登记时间的结束
    Date registStart= sb.parse(registrationStartTime+":00");
    Date registrEnd= sb.parse(registrationEndTime+":59");
    // 在筛选一次,筛选出符合在登记时间之内的登记
    ArrayList<Record> timePDFRecord = new ArrayList<>();
    for(Record rd: chooseRecord){
    //获取登记时间
    String registrationTime=rd.getStr("registrationTime");
    //转为data类型的时间
    Date registrTime= sb.parse(registrationTime);
    //如果获取的登记时间,等于筛选的时间段中的一个,则之间放入集合中
    if (registrTime.getTime() >= registStart.getTime() && registrTime.getTime() <= registrEnd.getTime() ){
    timePDFRecord.add(rd);
    }


           
          

  • 相关阅读:
    【Maven】项目打包-war包-Jar包[IDEA将项目打成war包]
    intellij idea 配置web 项目
    centos7启动iptables时报Job for iptables.service failed because the control process exited with error cod
    shell-运算符
    shell-流程控制
    shell-流程控制
    shell-变量,字符串,数组,注释,参数传递
    shell-变量,字符串,数组,注释,参数传递
    json解析
    json解析
  • 原文地址:https://www.cnblogs.com/xiaoniuniu886/p/10564675.html
Copyright © 2011-2022 走看看