如何使用指明MyDate在Android 2.1的比较系统的日期?如何使用、日期、系统、Android

2023-09-06 13:50:01 作者:deceit 谎言

在我的Andr​​oid应用程序,我是把日期和时间从数据库中。但我不能够得到从数据库中日期格式的日期到我的应用程序,日期是字符串格式,所以我不能够比较系统日期数据库日期。 如果我转换系统日期为字符串,那么我无法更新日期到数据库中反复出现的情况。我也想如果系统日期和数据库的日期相匹配来更新数据库的日期

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 is in string format, so i am not able to compare the system date to database date. if i convert the system date into string then i am not able to update the date into the database in recurring case. i also want to update the database date if the system date and database date is matched.

我怎么能做到这一点的是Android。

how can i achieve this is android.

在此先感谢。

推荐答案

您可以将字符串转换为日期是这样的:

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);

和返回字符串

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.