Format a date using the new date time API

后端 未结 3 650
[愿得一人]
[愿得一人] 2020-12-09 00:34

I was playing with the new date time API but when running this:

public class Test {         
    public static void main(String[] args){
        String dateF         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 01:02

    The right class for me was ZonedDateTime which includes both Time and Time Zone.

    LocalDate doesn't have the Time information so you get a UnsupportedTemporalTypeException: Unsupported field: HourOfDay.

    You can use LocalDateTime but then you don't have the Time Zone information so if you try to access that (even by using one of the predefined formatters) you will get a UnsupportedTemporalTypeException: Unsupported field: OffsetSeconds.

提交回复
热议问题