package com.mx.operationcenter.webframework.web.util; import lombok.SneakyThrows; import lombok.experimental.UtilityClass; import org.apache.commons.lang3.StringUtils; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Calendar; import java.util.Date; /** * 工程包名: com.mx.operationcenter.webframework.web.util * 项目名称: mx * 创建描述: heliangming 补充 * Creator: heliangming * Create_Date: 10:57 2019-08-14 * Updater: heliangming * Update_Date:10:57 2019-08-14 * 更新描述: heliangming 补充 * <if test="begin != null"> * AND RELEASE_TIME > #{begin} * </if> * <if test="end != null"> * AND RELEASE_TIME < #{end} * </if> **/ @UtilityClass public class TimeUtil { public static final DateTimeFormatter DEFAULT_FORMATTER_DAY = DateTimeFormatter.ofPattern("yyyy-MM-dd"); public static final DateTimeFormatter DEFAULT_FORMATTER_SS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); public LocalDate string2LocalDate(String day){ LocalDate localDate = null; if (StringUtils.isNotBlank(day)) { localDate = LocalDate.parse(day, DEFAULT_FORMATTER_DAY); } return localDate; } public LocalDateTime string2LocalDateTime(String day){ return LocalDateTime.parse(day,DEFAULT_FORMATTER_SS); } public String localDateTime2String(LocalDateTime day){ return day.format(DEFAULT_FORMATTER_DAY); } public LocalDateTime string2LocalDateTimeDayStrat(String day){ return LocalDate.parse(day, DEFAULT_FORMATTER_DAY).atStartOfDay(); } public LocalDateTime string2LocalDateTimeDayEnd(String day){ return LocalDate.parse(day, DEFAULT_FORMATTER_DAY).plusDays(1L).atStartOfDay(); } @SneakyThrows public Date string2Date(String str){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.parse(str); } @SneakyThrows//返回date的num天前后日期 public String inferenceDay(String date,int num){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date2 = sdf.parse(date); Calendar cal = Calendar.getInstance(); cal.setTime(date2); cal.add(Calendar.DATE, num); return new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); } public LocalDateTime start(String startTime){ return LocalDate.parse(startTime, DEFAULT_FORMATTER_DAY).atStartOfDay(); } public LocalDateTime end(String endTime){ return LocalDate.parse(endTime, DEFAULT_FORMATTER_DAY).plusDays(1).atStartOfDay(); } }
TimeUtil
最新推荐文章于 2021-02-13 15:56:40 发布