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("");
}
}
标签:判断,java,JSONObject,Date,01,date,区间,new,createTimeDate From: https://www.cnblogs.com/czzz/p/18003506https://blog.51cto.com/u_16175452/6827109
https://blog.51cto.com/u_16175430/7837429