在Android中比较两个字符串的日期和时间? [英] Compare Two String Date and Time in android?
本文介绍了在Android中比较两个字符串的日期和时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个字符串日期时间,如下所示:
I have Two String Datetime as follows:
String Date1 = "05-09-2013 10:46:10"
String Date2 = "06-09-2013 10:46:10"
我需要比较这些日期时间,我需要结果。
I Need to compare these datetimes and i need result.
推荐答案
try{
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String str1 = "12/10/2013";
Date date1 = formatter.parse(str1);
String str2 = "13/10/2013";
Date date2 = formatter.parse(str2);
if (date1.compareTo(date2)<0)
{
System.out.println("date2 is Greater than my date1");
}
}catch (ParseException e1){
e1.printStackTrace();
}
这篇关于在Android中比较两个字符串的日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文