How to Compare system date with mydate in android 2.1?

时间秒杀一切 提交于 2019-11-30 22:15:24
Caner

You can convert String to Date like this:

String str = "12/12/1912";
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date date = formatter.parse(str);

And back to String

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
System.out.println("Date is : " + formatter.format(date));

And Date has before and after methods and can be compared to each other.

By the way there is also a library called Joda, you can also check it out.

Try this code:

Calendar c = Calendar.getInstance();
    System.out.println("Current time => " + c.getTime());
    SimpleDateFormat df = new SimpleDateFormat("dd-MMMM");
    formattedDate = df.format(c.getTime());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!