JMeter: Converting extracted time stamp value to date format

对着背影说爱祢 提交于 2019-12-08 00:13:52

问题


I have to extract the timestamp value from a response and have to pass it as a parameter to next request. I have extracted the timestamp value from Regular Expression Extractor. Time stamp value is 1481086800000 Value to be passed is in the format(Month/Date/Year HH:mm)- 12/07/2016 10:30

Kindly provide your valuable suggestion on how to convert the extracted time stamp value into above date format.


回答1:


Following code directly converted epoch timestamp to AKST timezone. No need of two samplers as suggested in the comments.

Add JSR223 Sampler, select Groovy and add the following code:

import java.text.*;
//long timeStamp =  Long.parseLong(vars.get("time"));
Date date = new Date(1481086800000); //replace the long value with timeStamp you captured.
DateFormat formatter = new SimpleDateFormat("MM/dd/YYYY HH:mm");

TimeZone tzInAmerica = TimeZone.getTimeZone("America/Anchorage");
formatter.setTimeZone(tzInAmerica);
String dateFormatted = formatter.format(date);
vars.put("newDate", dateFormatted); //access new value using ${newDate}, in your script.
log.info(dateFormatted);

Screenshot reference:



来源:https://stackoverflow.com/questions/41461759/jmeter-converting-extracted-time-stamp-value-to-date-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!