欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java8中的时间处理6 - 格式化

程序员文章站 2022-03-01 12:40:54
...

下面是格式化和解析的粒子:

        LocalDate date = LocalDate.now();
        
        System.out.println(date);
        
        System.out.println(date.format(DateTimeFormatter.ofPattern("d::MMM::uuuu")));
        System.out.println(date.format(DateTimeFormatter.BASIC_ISO_DATE));


        LocalDateTime dateTime = LocalDateTime.now();
        
        System.out.println(dateTime);
        
        System.out.println(dateTime.format(DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss")));
        System.out.println(dateTime.format(DateTimeFormatter.BASIC_ISO_DATE));

        Instant timestamp = Instant.now();
        
        System.out.println(timestamp);

        
        LocalDateTime dt = LocalDateTime.parse("27::四月::2014 21::39::48",
                DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss"));
        System.out.println(dt);