4

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"
rAJ
  • 1,295
  • 5
  • 31
  • 66

1 Answers1

14

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'")
Szymon Stepniak
  • 40,216
  • 10
  • 104
  • 131
  • I tried this : `def aaa = testCase.testSuite.project.getPropertyValue("StartDateTime"); log.info aaa.format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");` Output : `Tue Aug 22 16:13:26 IST 2017:INFO:yyyy-MM-dd'T'HH:mm:ss.SSS'Z' ` – rAJ Aug 22 '17 at 10:44
  • @rAJ Try applying a hint from updated answer. I hope it helps. – Szymon Stepniak Aug 22 '17 at 10:51