java - 判断时间范围区间
JSONObject respObj = new JSONObject(s);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String startTimeStr = "2024-01-01";
String endTimeStr = "2024-01-31";
Date startTimDate = sdf.parse(startTimeStr); //string 日期 转换为 date
Date endTimDate = sdf.parse(endTimeStr); //string 日期 转换为 date
JSONObject dataObj = respObj.getJSONObject("data");
JSONArray list = dataObj.getJSONArray("list");
for (Object o : list) {
JSONObject listItem = (JSONObject) o;
long createTime = listItem.getLong("createTime");
Date createTimeDate = new Date(createTime); //时间戳转换为date
if (!createTimeDate.after(startTimDate) || !createTimeDate.before(endTimDate)){ //判断时间范围
System.out.println(createTimeDate);
}else{
System.out.println("");
}
}
https://blog.51cto.com/u_16175452/6827109
https://blog.51cto.com/u_16175430/7837429
本文来自博客园,作者:chuangzhou,转载请注明原文链接:https://www.cnblogs.com/czzz/p/18003506