Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OffsetDateTime.toString() removes seconds and nanoseconds when they are 0

Tags:

java

For example when I am trying to print such OffsetDateTime:

OffsetDateTime offsetDateTime = OffsetDateTime.of(2018, 3, 18, 0, 0, 0, 0, ZoneOffset.UTC);

output is:

2018-03-18T00:00Z

instead of

2018-03-18T00:00:00.000Z

Maybe you know are there any easier way to do it then implement own toString/converter method?

like image 743
PiterM Avatar asked Oct 23 '25 03:10

PiterM


1 Answers

From Java API: format(DateTimeFormatter formatter) Formats this date-time using the specified formatter.

I would guess the easiest for you would be to use:

OffsetDateTime.of(2018, 3, 18, 0, 0, 0, 0, ZoneOffset.UTC).format(DateTimeFormatter.ISO_DATE_TIME);
like image 135
Veselin Davidov Avatar answered Oct 27 '25 02:10

Veselin Davidov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!