Date和LocalDate格式化问题使用的方法不一样,不可以混用

    1. @Test
    2. public void testDate() {
    3. //Date使用SimpleDateFormat做格式化处理
    4. SimpleDateFormat df = new SimpleDateFormat("这个日期格式化=yyyyMMdd");
    5. Date date = new Date();
    6. String string = df.format(date);
    7. log.info(string);
    8. //LocalDate需要使用DateTimeFormatter来做格式化处理
    9. LocalDate now = LocalDate.now();
    10. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("这个本地日期格式化=yyyy-MM-dd");
    11. String formattedString = now.format(formatter);
    12. log.info(formattedString);
    13. }

    SimpleDateFormat 是格式对象调用日期
    DateTimeFormatter 是日期调用格式对象