Search code examples
datetimejmetertimestampperformance-testingunix-timestamp

JMeter - how to convert a human readable date time into Unix timestamp


How can human readable date time format(yyyy.mm.dd hh:mm:ss ) be converted into Unix timestamp?

For example I have following date 2019.07.12 08:00:00 that need to be converted into unix time format?

Is there a way to do this in JMeter?


Solution

  • Add a Flow Control Action and add in it a JSR223PreProcessor with this code

     def date = Date.parse("yyyy.MM.dd HH:mm:ss", yourDate)
    vars.put("date", date.getTime().toString())
    

    You can then use:

    ${date}

    If using JMeter 5.3, add groovy-dateutil to lib folder of JMeter, due to this regression :