Search code examples
groovyjmeterbeanshelljsr223

Convert the parsed T&Z timestamp to millisecond


1) In response, a time stamp returned and is in T&Z format, ex: “2018-10-09T10:10:00Z”.

2) I have parsed the date and saved in a variable(date1) using “Regular Expression Extractor”.

3) In the successive request I would need to use the parsed time but this time I want to use it in millisecond format for the next request.

4) Here is my sample snippet looks like in “BSF PreProcessor”, Here “date1” is a variable to which the value is parsed and extracted using Regular Expression Extractor.

Code snippet,

var time1 = vars.get(date1);
var timem1 = new Date(time1);
var timem1 = timem1.getTime();
vars.put("timem1",timem1); 

But the above code didn’t help. Can anyone please help me here?

Thanks in advance.


Solution

  • Please check the below;-

    String b1 = "2018-10-09T10:10:00Z";
    time=Date.parse("yyyy-MM-dd'T'HH:mm:ss'Z'", b1)
    // get epoch milis
    epoch_milis = time.getTime()
    log.info("Current date in the specified format:>>>>>>>>>>>> " + epoch_milis);
    

    enter image description here

    Please check if this helps.

    Also, it is recommended to use JSR223 instead of beanshell due to performance.