如何将JMeter中的时间转换为24小时格式,同时使用shiftTime函数将IST转换为UTC格式?
实际上,我正在尝试改变时间,我正在使用的应用程序是UTC,我正在使用IST 我使用了BeanShell预处理器和shiftTime函数如何将JMeter中的时间转换为24小时格式,同时使用shiftTime函数将IST转换为UTC格式?,jmeter,Jmeter,实际上,我正在尝试改变时间,我正在使用的应用程序是UTC,我正在使用IST 我使用了BeanShell预处理器和shiftTime函数 import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; int AddSeconds= 00; //this variable needs to be customized as per your need int AddMinutes= 392;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
int AddSeconds= 00; //this variable needs to be customized as per your need
int AddMinutes= 392; //this variable needs to be customized as per your need
int AddHours= 00; //this variable needs to be customized as per your need
Date now = new Date();
Calendar c = Calendar.getInstance();
c.setTime(now);
c.add(Calendar.SECOND, AddSeconds);
c.add(Calendar.MINUTE, AddMinutes);
c.add(Calendar.HOUR, AddHours);
Date NewTime = c.getTime();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String mytime = df.format(NewTime);
vars.put("NewTime",mytime);
轮班时间:
“${u timeShift(yyyy-MM-dd'HH:MM:ss.SSS'Z',PT393M,,)”
Bun当我在Jmeter中运行HTTP请求时,时间格式是12小时,而不是24小时
此外,时间转换的方式也很奇怪,我在过去2天中尝试了Stackoverflow的所有选项,但无法完成将IST转换为UTC的任务
这就是我在Jmeter Post body中使用的内容
这就是我得到的结果
这里的时间格式完全不匹配,在使用这些时间格式和函数时,请有人帮助我将IST正确转换为UTC。我认为您不能使用u timeShift()函数获取不同时区的日期,它将返回当前(默认)日期 因此,如果你需要在与你的时区不同的当前时间上加392分钟,你就必须去上课 示例代码:
${__groovy(def now = new Date(); use(groovy.time.TimeCategory) { def nowPlusOneYear = now + 392.minute; return nowPlusOneYear.format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"\,TimeZone.getTimeZone('IST')) },)}
演示:
如果需要获得UTC时间,只需将IST
更改为UTC
${__groovy(def now = new Date(); use(groovy.time.TimeCategory) { def nowPlusOneYear = now + 392.minute; return nowPlusOneYear.format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"\,TimeZone.getTimeZone('UTC')) },)}
更多信息:
还请注意,对于脚本编写,只需通过bean shell预处理器添加另一种方法即可,对我来说效果非常好 下面是要使用的代码。。。此处-IST和UTC之间的差值为325分钟
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
int AddSeconds= 00; //this variable needs to be customized as per your need
int AddMinutes= -325; //this variable needs to be customized as per your need
int AddHours= 00; //this variable needs to be customized as per your need
Date now = new Date();
Calendar c = Calendar.getInstance();
c.setTime(now);
c.add(Calendar.SECOND, AddSeconds);
c.add(Calendar.MINUTE, AddMinutes);
c.add(Calendar.HOUR, AddHours);
Date NewTime = c.getTime();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String mytime = df.format(NewTime);
vars.put("NewTime",mytime);
// NewTime is your jmeter variable