/** * 看看时间是星期几. * @param timeStr * @return */ private String getWeekDay(String timeStr) {
// 2020-12-21 05:15:00 // 不需要考虑时区 DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // df.setTimeZone(TimeZone.getTimeZone("GMT+12:00")); Date d = null; try { d = df.parse(timeStr); } catch (ParseException e) { e.printStackTrace(); return ""; }
// 看今天是星期几 Calendar cal = Calendar.getInstance(); cal.setTime(d); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
// DAY_OF_WEEK:周日是1,周1是2,周2是3……周6是7 // 转成正常的1-7 dayOfWeek--; if (dayOfWeek == 0) { dayOfWeek = 7; } return String.valueOf(dayOfWeek); }
|