android比较时间

来源:互联网 发布:linux中sync 编辑:程序博客网 时间:2024/04/28 21:56

SimpleDateFormat    formatter    =   new    SimpleDateFormat    ("yyyy-MM-dd HH:mm:ss");     
Date    curDate    =   new    Date(System.currentTimeMillis());//获取当前时间     
String    currentString    =    formatter.format(curDate);   

String appointString="2015-10-11 10:09:00";



public static boolean DateCompare(String s1,String s2) throws Exception {

//设定时间的模板
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//得到指定模范的时间
Date d1 = sdf.parse(s1);
Date d2 = sdf.parse(s2);
//比较
if(d1.getTime() - d2.getTime() >=0) {
//if(((d1.getTime() - d2.getTime())/(24*3600*1000)) >=0) {
//System.out.println("大于三天");
return true;
}else{
//System.out.println("小于三天");
return false;
}
}
0 0
原创粉丝点击