我正在尝试将巴西本地日期转换为 UTC 格式。我已经开发了我的解决方案,但我相信它可以改进。我一直在寻找其他问题,但没有成功。
我的问题是,当我使用以下方法处理Date对象时:
Instant endDateTime = questionDate.toInstant();
Run Code Online (Sandbox Code Playgroud)
我收到一个 UTC 日期,"2017-11-16T00:00:00Z"但这应该是巴西本地日期(不正确,因为它有尾随"Z"),当我尝试转换为 UTC 时,我收到相同的输出。
另一方面,如果我使用ZoneDateTimeclass 并使用LocalDateTimeobject构建日期,我会在输出中丢失秒数:"2017-11-16T02:00Z". 当我使用时会发生这种情况:
LocalTime.of(hour, minutes, seconds);
Run Code Online (Sandbox Code Playgroud)
我搜索LocalTime课堂,我认为这是因为分钟或秒,0但我不确定。
OffsetDateTime类"2017-11-16""2017-11-16T02:00:00Z"private static OffsetDateTime processDate(Date questionDate) {
Instant endDateTime = questionDate.toInstant();
ZoneId zoneId = ZoneId.of(ZONEID);
String [] date = endDateTime.toString().split("T");
LocalDateTime localDateTime = convertLocalTimeToUtc(date);
ZonedDateTime zonedDateTime = …Run Code Online (Sandbox Code Playgroud)