为了账号安全,请及时绑定邮箱和手机立即绑定

如何查找预期日期的星期几

如何查找预期日期的星期几

MM们 2023-09-27 14:34:08
我不知道如何找到我想要的一周中的某一天?例如 :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)会给你你所寻求的价值。



查看完整回答
反对 回复 2023-09-27
  • 1 回答
  • 0 关注
  • 91 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信