0

I am trying to convert milliseconds time to date-time (yyyy-MM-dd'T'HH:mm:ss'Z') format in UTC.

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' value is '1503478800000'

The output i am getting is :-

Tue Aug 22 18:13:59 IST 2017:INFO:2017-08-23T09:00:00Z

But i want to handle DST in the output :-

Tue Aug 22 18:13:59 IST 2017:INFO:2017-08-23T10:00:00Z
rAJ
  • 1,295
  • 5
  • 31
  • 66

1 Answers1

0

If you're on Java 8, I'd highly recommend using its new java.time API instead of 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')))
bdkosher
  • 5,753
  • 2
  • 33
  • 40