| | |
| | | package com.panzhihua.common.utlis; |
| | | |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.*; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | @Slf4j |
| | | public class DateUtils { |
| | |
| | | private static DateTimeFormatter format_yms = DateTimeFormatter.ofPattern("yyyyMM"); |
| | | private static DateTimeFormatter format_y = DateTimeFormatter.ofPattern("yyyy"); |
| | | |
| | | |
| | | public static String getNextDay(Date date,int day) { |
| | | LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
| | | return yyyyMMdd_format.format(Date.from(localDate.plusDays(day).atStartOfDay(ZoneId.systemDefault()).toInstant())); |
| | | } |
| | | /** |
| | | * 将日期对象格式化成指定的字符串格式 |
| | | * |
| | |
| | | long min = diff / nm; |
| | | |
| | | return (int)hour; |
| | | } public static int getDay(Date stardate, Date enddate) { |
| | | long nd = 1000 * 24 * 60 * 60; |
| | | long nh = 1000 * 60 * 60; |
| | | long nm = 1000 * 60; |
| | | long diff = enddate.getTime() - stardate.getTime(); |
| | | |
| | | long day = diff / nd; |
| | | |
| | | long hour = diff / nh; |
| | | |
| | | long min = diff / nm; |
| | | |
| | | return (int)day; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 结束时间与当前时间计算相差的月数 |
| | | * |