接口需要在报头中设置RFC1123时间我不能使用JMeter在beanshell中设置
我知道代码可以在java中工作:
SimpleDateFormat sdf3 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",Locale.US);
sdf3.setTimeZone(TimeZone.getTimeZone("GMT"));
String rfc1123_3 = sdf3.format(new Date());但是我不能在Beanshell脚本中运行它
发布于 2019-06-03 21:07:54
您必须在代码的开头添加import语句:
import java.text.SimpleDateFormat;请注意,您最好转向使用JSR223组件而不是Beanshell
发布于 2019-06-03 21:15:16
标题:
import java.time.*;
import java.time.format.*;代码:
print(OffsetDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.RFC_1123_DATE_TIME));输出:
Mon, 3 Jun 2019 13:19:56 GMT我使用的是java.time,这是一种现代的Java date and time API。你提到的SimpleDateFormat是出了名的麻烦而且很久以前就过时了,你不想用它。
链接
https://stackoverflow.com/questions/56427965
复制相似问题