-3

I have a java ZonedDateTime object in the following format

2017-01-16T21:03:10.712+09:00[Asia/Tokyo]

I want it to be displayed in the following format also as a ZonedDateTime object

16/01/2017 21:03

How can I do this?

kosta
  • 4,302
  • 10
  • 50
  • 104

1 Answers1

0

You can check out more information at this documentation. You need to use a DateTimeFormatter and provide a pattern to the printed version, like that:

ZonedDateTime zonedDateTime = ZonedDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
System.out.println("Default: \t"+ zonedDateTime);
System.out.println("Formated: \t"+ zonedDateTime.format(formatter));

Output:

Default:    2017-01-16T23:35:28.410-02:00[America/Sao_Paulo]
Formated:   16/01/2017 23:35

Checkout it working: http://ideone.com/0zcMJ6

Bruno
  • 2,889
  • 1
  • 18
  • 25