How to Compare system date with mydate in android 2.1?

后端 未结 2 917
攒了一身酷
攒了一身酷 2021-01-05 23:03

in my Android application, i am taking date and time from database. but i am not able to get the date in the \"Date\" Format from the database into my application, the date

相关标签:
2条回答
  • 2021-01-05 23:41

    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.

    0 讨论(0)
  • 2021-01-05 23:57

    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());
    
    0 讨论(0)
提交回复
热议问题