我不知道如何找到我想要的一周中的某一天?例如 :SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");Calendar calendar = Calendar.getInstance();String s="2019-10-07"; try { calendar.setTime(simpleDateFormat.parse(s)); if(Calendar.DAY_OF_WEEK == 2){ Toast.makeText(this, "Mo", Toast.LENGTH_SHORT).show(); } } catch (ParseException e) { e.printStackTrace(); }但它不能正确工作!日历的当前日期只是考虑的,不是我指定的日期。
1 回答

qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
Calendar.DAY_OF_WEEK
是一个常数7
,所以它工作正常,只是不是你期望的那样。您不应该Calendar
在新代码中使用(而是使用ThreeTenABP)。但calendar.get(Calendar.DAY_OF_WEEK)
会给你你所寻求的价值。
添加回答
举报
0/150
提交
取消