jmeter 将日期从 EST 转换为 UTC [英] jmeter convert date from EST to UTC

查看:21
本文介绍了jmeter 将日期从 EST 转换为 UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 API 响应中的日期.来自 API 的日期在 EST 中.我需要将 EST(技术上为 EDT)日期转换为 UTC,然后与来自另一个值为 UTC 格式的 API 响应的日期进行比较

I am working with dates that are on an API response. Date coming from API are in EST. I need to convert the EST (technically EDT) date to UTC and then compare with dates from another API response whose values are in UTC format

我正在尝试在 JMeter 中使用 Javascript 执行此操作.我有一个BSF 后处理器"作为我的HTTP 请求"采样器的子代.

I am trying to do this with Javascript in JMeter. I have a "BSF PostProcessor" as a child of my "HTTP Request" sampler.

我的输入:结束日期=2014-01-31T23:59:59

My input: endDate=2014-01-31T23:59:59

我尝试了几个选项,但没有一个能达到我期望的价值.他们都回到我的调试采样器作为..

I tried a few options but none of them get me the value I am expecting. They all come back on my debug sampler as..

myNewDate=无效日期

myNewDate=Invalid Date

dt1=无效日期

vars.put("myendDate", vars.get("endDate"));
var dt = new Date('myendDate');
vars.put("dt1", dt.toUTCString());

var myDate = new Date('${endDate}');
vars.put("myNewDate", myDate.toUTCString());


var myDate = new Date('${endDate}');
myDate.toISOString();
vars.put("myDate1", myDate);

我认为我的 BSF PostProcessor with Javascript as Language 在创建 Date 对象时遇到问题.

I think my BSF PostProcessor with Javascript as Language is having trouble creating the Date object.

请输入任何信息?

推荐答案

将 groovy-all.jar 添加到 jmeter/lib 文件夹

Add groovy-all.jar to jmeter/lib folder

并使用带有 Groovy 和编译缓存键的 JSR223Sampler 和以下代码:

And use JSR223Sampler with Groovy and Compilation Cache key and following code:

import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.util.Date;

SimpleDateFormat estFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
SimpleDateFormat gmtFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
TimeZone gmtTime = TimeZone.getTimeZone("GMT");
TimeZone estTime = TimeZone.getTimeZone("EST"); 
estFormat.setTimeZone(estTime);
gmtFormat.setTimeZone(gmtTime); 
String endDate = vars.get("endDate");
Date endDateAsDate= estFormat.parse(endDate);
vars.put("dt1", gmtFormat.format(endDateAsDate));

然后您可以使用 ${dt1}

You can then use ${dt1}

这篇关于jmeter 将日期从 EST 转换为 UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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