Java8- ZonedDateTime with DateTimeFormatter not recognizing the format

后端 未结 2 796
长发绾君心
长发绾君心 2021-01-02 16:32

I am using the ZonedDateTime with DateTimeFormatter of Java 8. When I try to parse my own pattern it doesn\'t recognizes and throws an exception.

    String          


        
2条回答
  •  情书的邮戳
    2021-01-02 17:16

    Here is an small example of using the ZonedDateTime with DateTimeFormatter of Java 8.

    public String currentDateTime() {
    
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("EEEE y-MM-d MMMM HH:m:s z Z'['VV']' 'Day:'D");
    
    return ZonedDateTime.now(ZoneId.of("Europe/Lisbon")).format(dateTimeFormatter);
        }
    

    The ZonedDateTime class permits you to create a date/time object with a time zone. The default time zone will be used; i.e., the time zone you have established on your computer. You can use the DateTimeFormatter class to display the time zone. In the Java code, the time zone is displayed as zone offset, zone name and zone ID. Note that the date time formatter pattern is "Z", "z", and "VV", respectively. The program also creates a date/time object and then adds the zone ID using the of method of the ZoneId class. Finally, a time zone is added to another date/time object using the of method of the ZoneOffset class.

提交回复
热议问题