如何找到预期日期的星期几
How to find day of week for Intended day
我不知道如何找到我想要的星期几?
例如:
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();
}
但它不能正常工作!刚刚考虑的日历的当前日期,不是我指定的日期。
Calendar.DAY_OF_WEEK
is a constant 7
so it's working correctly, just not how you expected. You should not be using Calendar
in new code (instead use the ThreeTenABP). But calendar.get(Calendar.DAY_OF_WEEK)
会给你想要的价值。
我不知道如何找到我想要的星期几?
例如:
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();
}
但它不能正常工作!刚刚考虑的日历的当前日期,不是我指定的日期。
Calendar.DAY_OF_WEEK
is a constant 7
so it's working correctly, just not how you expected. You should not be using Calendar
in new code (instead use the ThreeTenABP). But calendar.get(Calendar.DAY_OF_WEEK)
会给你想要的价值。