可以使用java.util.Calendar类来实现。首先,使用Calendar.getInstance()静态方法创建一个Calendar对象,然后使用setTime()方法将其设置为指定的日期,最后使用get()方法获取星期几(Calendar.DAY_OF_WEEK)。
代码示例:
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse("2022-09-12");
Calendar cal = Calendar.getInstance();
cal.setTime