JMeter: Converting extracted time stamp value to date format

爱⌒轻易说出口 提交于 2019-12-06 11:24:21

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:

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