优化
This commit is contained in:
@ -5,6 +5,8 @@ import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@ -157,4 +159,19 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
// long sec = diff % nd % nh % nm / ns;
|
||||
return day + "天" + hour + "小时" + min + "分钟";
|
||||
}
|
||||
|
||||
|
||||
public static LocalDate str2Localdate(String time,String format){
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
||||
LocalDate localDate = null;
|
||||
try {
|
||||
// 将字符串转换为 LocalDate
|
||||
localDate = LocalDate.parse(time, formatter);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("日期格式不正确,转换失败: " + e.getMessage());
|
||||
}
|
||||
return localDate;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user