如何比较字符串与日历的日期?

yos*_*i24 0 android calendar

我正在使用它来读取HTML项目列表.

while (postIt.hasNext()) {
    Element name = postIt.next();
    nameOf = name.text();

    String platform = postIt.next().text();

    //Get the URL
    Element url = name.select("a").first();
    urlString = url.attr("href");

    //Get the Genre of the item
    String genre = postIt.next().text();

    //Get the date
    Date = postIt.next().text();
}
Run Code Online (Sandbox Code Playgroud)

我想做的是比较日期字符串与Android设备上当前日期的字符串?我将如何通过日历这样做呢?

nic*_*ild 5

我会用Date和做这个SimpleDateFormat

Date d = new Date(); //todays date (current time)

//set the pattern here to look like the pattern you are expecting in your 'Date' variable
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

String formattedDate = sdf.format(d);
//for today the string would look like this: "2011-08-26"

boolean isToday = formattedDate.equals(Date); //your answer...
Run Code Online (Sandbox Code Playgroud)

如果您不熟悉SimpleDateFormatter,请查看此处文档.它有很多有用的信息来设置您的模式.