parent
22ea7f364e
commit
73f46df2b9
Binary file not shown.
@ -1,48 +1,48 @@
|
||||
package com.baizhi.swing.utils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class DateTimeUtils {
|
||||
public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static LocalDate parseLocalDate(String dateStr) {
|
||||
if (dateStr == null || dateStr.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LocalDate.parse(dateStr, DATE_FORMATTER);
|
||||
} catch (Exception e) {
|
||||
System.err.println("无法解析日期: " + dateStr);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String localDateToString(LocalDate date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
return date.format(DATE_FORMATTER);
|
||||
}
|
||||
|
||||
public static LocalDateTime parseLocalDateTime(String dateTimeStr) {
|
||||
if (dateTimeStr == null || dateTimeStr.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LocalDateTime.parse(dateTimeStr, DATE_TIME_FORMATTER);
|
||||
} catch (Exception e) {
|
||||
System.err.println("无法解析日期时间: " + dateTimeStr);// 打印错误信息
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String localDateTimeToString(LocalDateTime date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
return date.format(DATE_TIME_FORMATTER);
|
||||
}
|
||||
}
|
||||
package com.baizhi.swing.utils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class DateTimeUtils {
|
||||
public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static LocalDate parseLocalDate(String dateStr) {
|
||||
if (dateStr == null || dateStr.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LocalDate.parse(dateStr, DATE_FORMATTER);
|
||||
} catch (Exception e) {
|
||||
System.err.println("无法解析日期: " + dateStr);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String localDateToString(LocalDate date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
return date.format(DATE_FORMATTER);
|
||||
}
|
||||
|
||||
public static LocalDateTime parseLocalDateTime(String dateTimeStr) {
|
||||
if (dateTimeStr == null || dateTimeStr.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LocalDateTime.parse(dateTimeStr, DATE_TIME_FORMATTER);
|
||||
} catch (Exception e) {
|
||||
System.err.println("无法解析日期时间: " + dateTimeStr);// 打印错误信息
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String localDateTimeToString(LocalDateTime date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
return date.format(DATE_TIME_FORMATTER);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue