这里是Boomi / Java / Groovy noob ...我从一个日期(从第三方供应商那里发送给我们)开始,其格式如下:2018-04-18 12:15:00.000000(没有'T' ),我们被告知是在美国/芝加哥TZ。我最终需要以以下日期格式(带有“ T”并添加偏移量)获取输出:
2018-04-18T12:15:00.000000-06:00
-或-
2018-04-18T12:15:00.000000-05:00(取决于芝加哥每年特定时间的当地时间)
我一直在尝试多种简单组合,包括SimpleDateFormat,ZoneID.of,ZonedDateTime.ofInstant,LocalDateTime.ofInstant,LocalDateTime.parse等。到目前为止,我在寻找正确的组合方面惨遭失败。
任何帮助将不胜感激!
您可以将其读取为LocalDateTime,然后将其移至芝加哥时区的同一时间:
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
String input = "2018-04-18 12:15:00.000000"
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.n")
ZoneId chicago = ZoneId.of("America/Chicago")
LocalDateTime localTime = LocalDateTime.parse(input, format)
ZonedDateTime chicagoTime = localTime.atZone(chicago)
println chicagoTime
打印:
2018-04-18T12:15-05:00[America/Chicago]
如果仅需要OffsetDateTime,则可以使用方法toOffsetDateTime()
println chicagoZonedTime.toOffsetDateTime()
哪些印刷品:
2018-04-18T12:15-05:00