时间日期操作:判断当前日期是否是周四,不是计算下一个周四

private static final String START_TIME = "10:00:00";

public JSONObject validActivity() {
		JSONObject resultJson = new JSONObject();
		//获取当前日期
		LocalDateTime now = LocalDateTime.now();
		DayOfWeek dayOfWeek = now.getDayOfWeek();
		boolean flag = true;
		//如果不是周四或者时间早于10点
		if (dayOfWeek.getValue() != DayOfWeek.THURSDAY.getValue() && now.getHour() < 10){
			flag = false;
		}
		//如果不在活动时间,返回下场活动开始时间
		if(!flag){
                        //计算下一个周四的日期
			LocalDate localDate = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.of(4)));
			String startDate = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
			startDate = startDate+" "+START_TIME;
			resultJson.put("nextDate", startDate);
		}
		resultJson.put("isStart", flag);
		return resultJson;
	}
posted @ 2021-11-26 10:40  juyss  阅读(167)  评论(0编辑  收藏  举报