我正在尝试将毫秒时间转换为UTC格式的日期时间(yyyy-MM-dd' T' HH:mm:ss' Z')格式。
def StartDateTimeNew = testCase.testSuite.project.getPropertyValue("StartDateTime").toLong()
def Startdate = new Date(StartDateTimeNew).format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone('UTC'));
log.info Startdate
'的startDateTime'价值是' 1503478800000'
我得到的输出是: -
Tue Aug 22 18:13:59 IST 2017:INFO:2017-08-23T09:00:00Z
但我想在输出中处理DST: -
Tue Aug 22 18:13:59 IST 2017:INFO:2017-08-23T10:00:00Z
答案 0 :(得分:0)
如果您使用的是Java 8,我强烈建议您使用新的java.time API而不是java.util.Date
import java.time.*
import java.time.format.DateTimeFormatter
// this converts the millis to the ZonedDateTime representation
def currentZone = ZoneId.systemDefault() // or whatever the appropriate zone is
def startdate = ZonedDateTime.ofInstant(Instant.ofEpochMilli(startDateTimeLong), currentZone)
// to format in UTC
def fmt = startdate.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of('UTC')))