package com; import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ; public class Test { public static void main(String[] args) { String s1="2018-01-25"; String s2="2018-02-25"; java.text.DateFormat df=new java.text.SimpleDateFormat("yyyy-MM-dd"); java.util.Calendar c1=java.util.Calendar.getInstance(); java.util.Calendar c2=java.util.Calendar.getInstance(); try { c1.setTime(df.parse(s1)); c2.setTime(df.parse(s2)); }catch(java.text.ParseException e){ System.err.println("格式不正确"); } int result=c1.compareTo(c2); if(result==0) System.out.println("c1相等c2"); else if(result<0) System.out.println("c1小于c2"); else System.out.println("c1大于c2"); System.out.println(completdate(s1,s2)); } public static int completdate(String starttime,String endtime){ java.text.DateFormat df=new java.text.SimpleDateFormat("yyyy-MM-dd"); java.util.Calendar c1=java.util.Calendar.getInstance(); java.util.Calendar c2=java.util.Calendar.getInstance(); try { c1.setTime(df.parse(starttime)); c2.setTime(df.parse(endtime)); }catch(java.text.ParseException e){ System.err.println("格式不正确"); } int result=c1.compareTo(c2); return result; } }
原文地址:http://congwa.blog.51cto.com/6640213/1649778