2

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?

JacekM
  • 4,041
  • 1
  • 27
  • 34
V G
  • 23
  • 4
  • There's a thread that asks for something similar, but the conversion is the other way round, from timestamp to date. Nevertheless you may find it helpful: https://stackoverflow.com/questions/41461759/jmeter-converting-extracted-time-stamp-value-to-date-format – JacekM Aug 19 '20 at 23:08
  • Do you want to assume the time in in the local timezone or UTC? Assume daylight savings time is in effect for the current time? – chux - Reinstate Monica Aug 19 '20 at 23:09
  • Time is in UTC , and I need to convert it into Unix timestamp. – V G Aug 20 '20 at 06:48

2 Answers2

2

You can use the following __groovy() function:

${__groovy(new SimpleDateFormat('yyyy.MM.dd HH:mm:ss').parse('2019.07.12 08:00:00').getTime(),)}

Demo:

enter image description here

More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

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 :

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
  • Hi, I tried this but unfortunately, I'm getting the following exception: 2020-08-20 17:16:55,084 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static java.util.Date.parse() is applicable for argument types: (String, String) values: [yyyy.MM.dd HH:mm:ss, 2020.08.21 08:00:00] Possible solutions: parse(java.lang.String), wait(), clone(), grep(), any(), use([Ljava.lang.Object;) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(Groov – V G Aug 20 '20 at 14:15