I am using Java 11.
I have a datetime string which looks like this
"2023-02-17T03:56:50.254"
But I know it represents a point in time in UTC time zone.
How do I parse this string taking into account it's actually in UTC (the parsing has to be independent of my default JVM time-zone)?
And then how do I convert it to another string which represents the same date/time in e.g. America/NewYork time zone?
There are many parsing examples here but none of them seems to represent exactly my case.
First, parse the string into a
LocalDateTime, because that's all there is in the string - a date and a time.Then, you can convert it to a
ZonedDateTimeor anInstant, depending on your interpretation - whether this is a date and time in theUTCzone, or a point in time.After you have either of those, you can use
withZoneSameInstant/atZonerespectively to put it into another zone.