How to format a ZonedDateTime to a String?

前端 未结 2 1230
既然无缘
既然无缘 2020-12-29 18:27

I want to convert a ZonedDateTime to a String in the format of ("dd/MM/yyyy - hh:mm"). I know this is possible in Joda-Time

2条回答
  •  长发绾君心
    2020-12-29 18:57

    You can use java.time.format.DateTimeFormatter. https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

    Here there is an example

    ZonedDateTime date = ZonedDateTime.now();
    
    System.out.println(DateTimeFormatter.ofPattern("dd/MM/yyyy - hh:mm").format(date));
    

提交回复
热议问题