开发者

How can I read and parse a date and time in Android?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜