How can I get current time in 24 hours format in JMeter.
I tried ${__time(hh:mm a,)}
but it results in AM/PM format.
In Apache JMeter 5.2, current time can be captured in User defined variable and then used in Rest payloads as following screenshot:
expression - ${__timeShift(yyyy-MM-dd'T'HH:mm:ss'.000+05:30',,PT0S,,)}
output - "2020-06-06T18:10:59.000+05:30"
Here, date and time format can be changed as per the need.
Once current date and time is captured in user defined variable then it can be used as "${now-date-time}"
in REST requests.
It could also be possible that we face a scenario where there should be gap of, let's say, 1second between start time and end time while constructing request. In such case, following expressions can help:
now-date-time : ${__timeShift(yyyy-MM-dd'T'HH:mm:ss'.000+05:30',,PT0S,,)}
now-date-time-plus-one-second : ${__timeShift(yyyy-MM-dd'T'HH:mm:ss'.000+05:30',,PT1S,,)}
Following example better explains it:
As per How to Use JMeter Functions guide JMeter's __time() function output can be controlled via SimpleDateFormat class patterns.
Looking into JavaDoc:
a
letterH
for 0-24 hours or lowercase k
for 1-23 hoursSo change function to ${__time(HH:mm,)}
and that should be it