代码1:

//当前时间比较一个时间超过六个月输出1
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -6);
String time = sdf.format(cal.getTime());
System.out.println(time);
if(sdf.parse(time).after(sdf.parse("2018-06-29 15:58:37"))){
    System.out.println(1);
}

 

代码2:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -6);
String time = "2018-6-29 15:45:51";
System.out.println(time);
String pwdTime = sdf.format(new Date());
System.out.println(pwdTime);
if(pwdTime.compareTo(new String())>0){
    System.out.println(1);
}

 

posted on 2018-12-29 17:19  月零Ray  阅读(538)  评论(0编辑  收藏  举报