向不带';在Boomi-Java/quot;“Groovy”;脚本映射函数

向不带';在Boomi-Java/quot;“Groovy”;脚本映射函数,java,datetime,groovy,timezone-offset,boomi,Java,Datetime,Groovy,Timezone Offset,Boomi,Boomi/Java/Groovy noob在这里。。。我从一个日期开始(由第三方供应商发送给我们),格式如下:2018-04-18 12:15:00.000000(no'T'),我们被告知是在美国/芝加哥TZ。我最终需要的是获得以下日期格式的输出(添加“T”和偏移量): 2018-04-18T12:15:00.000000-06:00 -或 2018-04-18T12:15:00.000000-05:00 (取决于芝加哥每年特定时间的当地时间) 我一直在尝试SimpleDateFormat、Z

Boomi/Java/Groovy noob在这里。。。我从一个日期开始(由第三方供应商发送给我们),格式如下:2018-04-18 12:15:00.000000(no'T'),我们被告知是在美国/芝加哥TZ。我最终需要的是获得以下日期格式的输出(添加“T”和偏移量):

2018-04-18T12:15:00.000000-06:00

-或

2018-04-18T12:15:00.000000-05:00 (取决于芝加哥每年特定时间的当地时间)

我一直在尝试SimpleDateFormat、ZoneID.of、ZoneDateTime.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()

其中打印:

2018-04-18T12:15-05:00

您可以将其读取为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()

其中打印:

2018-04-18T12:15-05:00

回答得好,谢谢。只有格式模式字符串中的
.n
错误
n
表示纳秒,仅当秒上有九位小数时才正确。这里有六个小数,因此您需要使用
.SSSSSS
(当小数为
000000
时,您当然不会发现错误)。回答得好,谢谢。只有格式模式字符串中的
.n
错误
n
表示纳秒,仅当秒上有九位小数时才正确。这里有六个小数,因此您需要使用
.SSSSSS
(当小数为
000000
时,您当然不会发现错误)。