![JAR search and dependency download from the Maven repository](/logo.png)
cn.t.util.common.DateUtil Maven / Gradle / Ivy
package cn.t.util.common;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class DateUtil {
private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/**
* 获取当天字符串日期
* @return xxx
*/
public static String nowDateString() {
return LocalDate.now().format(dateFormatter);
}
/**
* 获取当天字符串时间
* @return xxx
*/
public static String nowDateTimeString() {
return LocalDateTime.now().format(dateTimeFormatter);
}
/**
* 解析日期
* @param str xxx
* @return xxx
*/
public static LocalDate parseLocalDate(String str) {
return LocalDate.parse(str, dateFormatter);
}
/**
* 格式化日期
* @param localDate xxx
* @return xxx
*/
public static String formatLocalDate(LocalDate localDate) {
return localDate.format(dateFormatter);
}
/**
* 解析时间
* @param str xxx
* @return xxx
*/
public static LocalDateTime parseLocalDateTime(String str) {
return LocalDateTime.parse(str, dateTimeFormatter);
}
/**
* 格式化时间
* @param localDateTime xxx
* @return xxx
*/
public static String formatLocalDateTime(LocalDateTime localDateTime) {
return localDateTime.format(dateTimeFormatter);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy