Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert milliseconds to yyyy-MM-dd date-time format in Groovy

Tags:

groovy

soapui

I am trying to convert milliseconds (e.g : 1503478800000) to yyyy-MM-ddTHH:mm:ss.SSS'Z' (e.g : 2017-08-23T09:00:000Z) date-time format. Milliseconds value stored in the Soapui Global variable.

def testCase = messageExchange.modelItem.testCase;
def NewDateTime = testCase.testSuite.project.getPropertyValue("StartDateTime").toInteger();
log.info NewDateTime.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

Error popup display :-

For input string: "1503478800000"
like image 933
rAJ Avatar asked Dec 19 '22 04:12

rAJ


1 Answers

With Groovy you can do it with Date.format(String format) method, e.g.

def millis = testCase.testSuite.project.getPropertyValue("StartDateTime").toLong()

log.info new Date(millis).format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
like image 129
Szymon Stepniak Avatar answered May 09 '23 06:05

Szymon Stepniak