天天看點

LocalDate和LocalDateTime日期格式化廢話少說,直接上代碼

LocalDate和LocalDateTime日期格式化

  • 廢話少說,直接上代碼

廢話少說,直接上代碼

public static void main(String[] args) throws Exception {
        LocalDate curDay = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        System.out.println(curDay.format(formatter));
        formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println(LocalDateTime.now().format(formatter));
    }
           

運作結果:

LocalDate和LocalDateTime日期格式化廢話少說,直接上代碼