Vinícius Britto :
I need to do a LocalDateTime
conversion of a UTC date to another LocalDateTime
variable considering a specific timezone tz.
During my research I found many solutions, but they all convert the LocalDateTime
to another type, like ZonedDateTime
.
I need something like that, but LocalDateTime
wont work with ZoneId
:
LocalDateTime output = input.getInitDate().of(ZoneId.of(tz))
Considering a -3 timezone:
input: 2019-12-03T18:24:07
output: 2019-12-03T15:24:07
Eng.Fouad :
You need to convert it first to ZonedDateTime
, change the timezone, and then extract LocalDateTime
from that:
ZoneId from = ...;
ZoneId to = ...;
LocalDateTime input = ...;
LocalDateTime output = input.atZone(from).withZoneSameInstant(to).toLocalDateTime();
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=415520&siteId=1