liujie
2026-05-21 0e5d431f85612bf3abc0515fb6e46e500b5cdfe1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);
    }
}