package com.estate.expert.common.utils;
|
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeParseException;
|
|
/**
|
* @author ligf
|
* @Description
|
* @date 2023-09-07
|
**/
|
public class StringCommonUtils {
|
|
public static boolean validateDateStr(String input, String pattern) {
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
try {
|
LocalDate.parse(input, formatter);
|
return true;
|
} catch (DateTimeParseException e) {
|
return false;
|
}
|
}
|
|
public static LocalDateTime parseLocalDateTime(String input, String pattern) {
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
return LocalDateTime.parse(input, formatter);
|
}
|
|
public static String getDay(LocalDateTime time, String pattern) {
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
// time to string yyyy-MM-dd
|
String day = formatter.format(time);
|
return day;
|
}
|
|
public static void main(String[] args) {
|
|
String pattern = "yyyy-MM-dd";
|
String result = getDay(LocalDateTime.now(), pattern);
|
System.out.println(result);
|
}
|
}
|