0

我有以下日期格式:DateFormat df = new SimpleDateFormat("EEEEE, LLLL d"); 和以下字符串数组:

String[] Days = {
        "Tuesday, January 1",
        "Monday, January 21",
        "Sunday, February 10",
        "Tuesday, February 12",
        "Wednesday, February 13",
        "Monday, February 18",
        "Sunday, February 24",
        "Tuesday, March 26",
        "Wednesday, March 27",
        "Thursday, March 28",
        "Friday, March 29",
        "Monday, April 1",
        "Tuesday, April 2",
        "Thursday, May 2",
        "Friday, May 3",
        "Thursday, May 9",
        "Wednesday, May 15",
        "Thursday, May 16",
        "Monday, May 27",
        "Thursday, July 4",
        "Wednesday, August 7",
        "Thursday, August 8",
        "Friday, August 9",
        "Thursday, August 15",
        "Monday, September 2",
        "Thursday, September 5",
        "Friday, September 6",
        "Saturday, September 14",
        "Thursday, September 19",
        "Friday, September 20",
        "Thursday, September 26",
        "Friday, September 27",
        "Monday, October 14",
        "Tuesday, October 15",
        "Wednesday, October 16",
        "Thursday, October 17",
        "Friday, November 1",
        "Sunday, November 3",
        "Tuesday, November 5",
        "Monday, November 11",
        "Thursday, November 28",
        "Sunday, December 8",
        "Wednesday, December 25"
};

我该如何进行比较,所以假设df=Friday, September 27这将是真的,因为字符串在数组Days中具有值“9 月 27 日星期五”。

我做了以下但我的小部件FC:

    for (int j=0; j<=suspendedDates.length;j++) {
        if (df.format(new Date()) == suspendedDates[j]) {
            views.setTextViewText(R.id.tvParkStatus, "Parking Suspended");
        }
        else {
            views.setTextViewText(R.id.tvParkStatus, "Parking Not Suspended");
        }
    }
4

2 回答 2

1

不确定为什么需要DateFormatter,因为看起来您有一个字符串和一个字符串数组作为输入。只需检查字符串:

Arrays.asList(Days).contains("Friday, September 27");
于 2013-09-27T16:30:50.713 回答
1

这应该可以解决问题:

DateFormat df = new SimpleDateFormat("EEEE, MMMM d", Locale.US);
System.out.println(Arrays.asList(Days).contains(df.format(Calendar.getInstance(Locale.US).getTime())));

输出 :

真的

于 2013-09-27T16:31:05.460 回答