I have a date and time 2011-02-28 07:00:52
as a string. How can I read it and then parse it as a date and time to compare it to an Android system tim开发者_JS百科e and date?
String time; // your string representing the time
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMddHHmmss");
Date startDate = dateFormatter.parse(time);
and
new Date()
will give you a date representing the current date and time.
When comparing dates, once you have the date object as shown by kett_chup, use date.getTime() which gives you the milliseconds and you can then easily compare with another date.getTime() to determine if one date came before or after the other.
精彩评论