LocalDate获取指定格式日期

使用JDK8中的LocalDate类:

    public static void main(String[] args) {
        LocalDate nowDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        String format = nowDate.format(formatter);
        System.out.println(format);
    }

控制台输出: 

20191023
发布了187 篇原创文章 · 获赞 146 · 访问量 49万+

猜你喜欢

转载自blog.csdn.net/qq_37495786/article/details/102707513