package com.monkeyk.sos.infrastructure; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; 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 Date now() { return new Date(); } public static String toDateTime(LocalDateTime date) { return toDateTime(date, DEFAULT_DATE_TIME_FORMAT); } public static String toDateTime(Date date) { return toDateTime(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(), DEFAULT_DATE_TIME_FORMAT); } public static String toDateTime(LocalDateTime dateTime, String pattern) { return dateTime.format(DateTimeFormatter.ofPattern(pattern, Locale.SIMPLIFIED_CHINESE)); } }