使用步骤
- 通过Calendar.getInstance()创建 Calendar对象c;
- 通过c.set(year, month,day); 设置时间日历
- 处理返回结果(c.get(c.DAY_OF_WEEK)+3)%7
细节说明
- c.get(c.DAY_OF_WEEK) 返回的是星期几
- 但是需要手动处理 +3与你的本地星期相差数
- % 7 按七进制取
代码
public String dayOfWeek(int year,int month,int day){
Calendar c = Calendar.getInstance();
c.set(year, month, day);
return "星期" + (c.get(c.DAY_OF_WEEK)+3)%7;
}
图示