我有以下日期格式:DateFormat df = new SimpleDateFormat("EEEEE, LLLL d");
和以下String数组:
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");
}
}
答案 0 :(得分:1)
不确定为什么需要 DateFormatter ,因为看起来你有一个字符串和一个字符串数组作为输入。只需检查字符串:
Arrays.asList(Days).contains("Friday, September 27");
答案 1 :(得分:1)
这应该可以解决问题:
DateFormat df = new SimpleDateFormat("EEEE, MMMM d", Locale.US);
System.out.println(Arrays.asList(Days).contains(df.format(Calendar.getInstance(Locale.US).getTime())));
输出:
真