JMeter:将提取的时间戳值转换为日期格式


美国时间,毫秒级的时间戳转换成时间格式:

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

亚洲时间,秒级别的转换成时间格式

import java.text.*; 
//long timeStamp = Long.parseLong(vars.get("time")); 
Date date = new Date(Long.parseLong(String.valueOf(${register_time}).concat("000"))); //用捕获的时间戳替换长值。转换成秒的形式,就是把字符串变成long类型的.java是静态语言,对类型有要求
DateFormat formatter = new SimpleDateFormat("MM-dd-YYYY HH:mm:ss"); 

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM