Forum Discussion

karelkremel's avatar
karelkremel
Occasional Contributor
8 years ago

converting datetime to unix timestamp

i believe i'm just missing something, it should be easy.....

i'm just trying to convert a human readable datetime to unix timestamp

 

2017-09-08 14:00:00+02               to                 1504872000

 

the thing is, i use a testcase variable in a rest request: ${#TestCase#pvr_program_id}} but no matter how did i convert it to date and then tried to format it, it never worked....

 

and then i've tried to convert current datetime to unixtime but it failed to... as if soapui/groovy doesn't know what Unix is....

${=new Date().format("U")}

    • karelkremel's avatar
      karelkremel
      Occasional Contributor

      for some reason i'm getting an error about unparseable date when i read it from test case propriety

      sample value: 1504872000000

       

       

      def dateFormat = 'yyyy-MM-dd HH:mm:ssZ'
      
      def start_date_raw = testRunner.testCase.getPropertyValue("start_date").substring(0,10)
      def end_date_raw =  testRunner.testCase.getPropertyValue("end_date").substring(0,10)
      
      def start_date_unix = Date.parse(dateFormat, start_date_raw).time
      def end_date_unix = Date.parse(dateFormat, end_date_raw).time
      
      testRunner.testCase.setPropertyValue( "start_date", start_date_unix )
      testRunner.testCase.setPropertyValue( "end_date", end_date_unix )