Fetch current time in 24 hours format in JMeter

后端 未结 2 1269
小蘑菇
小蘑菇 2020-12-22 03:32

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.

相关标签:
2条回答
  • 2020-12-22 03:58

    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:

    0 讨论(0)
  • 2020-12-22 04:00

    As per How to Use JMeter Functions guide JMeter's __time() function output can be controlled via SimpleDateFormat class patterns.

    Looking into JavaDoc:

    • you don't need a letter
    • you need to use capital H for 0-24 hours or lowercase k for 1-23 hours

    So change function to ${__time(HH:mm,)} and that should be it

    0 讨论(0)
提交回复
热议问题