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