spring-oauth-server/src/main/java/com/monkeyk/sos/infrastructure/DateUtils.java

46 lines
1.0 KiB
Java

package com.monkeyk.sos.infrastructure;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
/**
* 日期处理工具类
*
* @author Shengzhao Li
*/
public abstract class DateUtils {
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
/**
* Private constructor
*/
private DateUtils() {
}
public static LocalDateTime now() {
return LocalDateTime.now();
}
public static String toDateTime(LocalDateTime date) {
return toDateTime(date, DEFAULT_DATE_TIME_FORMAT);
}
public static String toDateTime(LocalDateTime dateTime, String pattern) {
return dateTime.format(DateTimeFormatter.ofPattern(pattern, Locale.SIMPLIFIED_CHINESE));
}
public static String toDateText(LocalDate date, String pattern) {
if (date == null || pattern == null) {
return null;
}
return date.format(DateTimeFormatter.ofPattern(pattern, Locale.SIMPLIFIED_CHINESE));
}
}