hitch这个方法中有个Date参数,可以传进来一个日期,例如2021-12-20 10:22:32,parseJSON这个方法中有三个集合,里面的date是一堆数据,都是一样的,现在需要让year这个集合按照年初,年末这个时间区间取值,mouth按照月初月末区间进行取值,day集合也是同样如此,我尝试将hitch方法中Date这个参数用hutool 的DateUtil.beginOfYear这种方式进行取年初年末等,但是不知道怎么让三个集合按照特定的区间取值。
public List<Map> hitch(String stId, String Date) {
}
public List<Map> parseJSON(String jsonData) {
JSONObject year = new JSONObject();
year.put("年", date);
JSONObject mouth = new JSONObject();
mouth.put("月", date);
JSONObject day = new JSONObject();
day.put("日", date);
}
得到初末日期,算差值.偏移取值
有时候我们需要计算两个日期之间的时间差(相差天数、相差小时数等等),Hutool将此类方法封装为between方法:
日期或时间的偏移指针对某个日期增加或减少分、小时、天等等,达到日期变更的目的。Hutool也针对其做了大量封装
Date的函数自己去看看啦,分别按照取年值月值日值即可
区间取值用Calendar函数
public static String getDatePoor(Date endDate, Date nowDate) {
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = endDate.getTime() - nowDate.getTime();
// 计算差多少天
long day = diff / nd;
// 计算差多少小时
long hour = diff % nd / nh;
// 计算差多少分钟
long min = diff % nd % nh / nm;
// 计算差多少秒//输出结果
// long sec = diff % nd % nh % nm / ns;
return day + "天" + hour + "小时" + min + "分钟";
}