-2

I'm trying to perform a simple conversion from a set of date strings to ZonedDateFormat:

String dateString = "2034-09-03T00:00:00Z";
String date2String = "2023-01-20T13:45:24.548Z";

Parsing with the ZonedDateFormat works with the decimals but doesn't for the other string. How would I go about doing this?

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
lil chogomo
  • 41
  • 1
  • 1
  • 6
  • 1
    When happened when you tried `ZonedDateTime.parse`? – Jon Skeet Aug 17 '23 at 17:20
  • 1
    `Instant.parse( "2034-09-03T00:00:00Z" ).atZone( ZoneId.of( "your-zone-goes-here" ) )` – Basil Bourque Aug 17 '23 at 20:03
  • 1
    The one-arg `ZonedDateTime.parse()` parses both of your strings fine on my Java 18. What do you mean that it does not work, and which of the strings is “the other string”? Please specify exact observed result (whether error message or wrong output or whatever). And also paste the code that didn’t work. Also what makes you think you want a `ZonedDateTime`? `Instant` would represent your strings just fine. – Ole V.V. Aug 17 '23 at 23:17

0 Answers0