java日期比较
- 摘要:importjava.util.*;importjava.text.DateFormat;importjava.text.SimpleDateFormat;publicclassfdf{/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubinti=compare("2011-03-19","2009-09-11");System.out.println("i="+i);
- 标签:Java
import java.util.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class fdf {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i=compare("2011-03-19","2009-09-11");
System.out.println("i="+i);
}
public static int compare(String date1,String date2)
{
DateFormat df=new SimpleDateFormat("yyyy-mm-dd");
try
{
Date t1= df.parse(date1);
Date t2= df.parse(date2);
if(t1.getTime()>t2.getTime())
{
System.out.println("03-19大");
return 1;
}
else if(t1.getTime()<t2.getTime())
{
System.out.println("t1<t2");
return 0;
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
return 0;
}
}