import org.springframework.util.StringUtils; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Objects; public class DateUtil { /** * @param smallDate * @param bigDate * @desc 获取两个日期之间的天数 */ public static int getDaysBetween(String smallDate, String bigDate) { try { // 日期格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); // 获取两个日期的时间戳 Calendar cal = Calendar.getInstance(); cal.setTime(sdf.parse(smallDate)); long smallTime = cal.getTimeInMillis(); cal.setTime(sdf.parse(bigDate)); long bigTime = cal.getTimeInMillis(); // 相差的日期 long days = (bigTime - smallTime) / (1000 * 3600 * 24); return Integer.parseInt(String.valueOf(days)); } catch (Exception e) { throw new R
日期工具类
最新推荐文章于 2024-08-14 23:43:29 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)