JMeter:将提取的时间戳值转换为日期格式 [英] JMeter: Converting extracted time stamp value to date format

查看:1355
本文介绍了JMeter:将提取的时间戳值转换为日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从响应中提取时间戳记值,并将其作为参数传递给下一个请求. 我已经从Regular Expression Extractor中提取了时间戳记值. 时间戳记值为1481086800000 要传递的值的格式为(Month/Date/Year HH:mm)-12/07/2016 10:30

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.

推荐答案

以下代码直接将epoch timestamp转换为AKST timezone.无需注释中建议的两个采样器.

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

添加 JSR223采样器,选择Groovy并添加以下代码:

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);

屏幕截图参考:

这篇关于JMeter:将提取的时间戳值转换为日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆