美國時間,毫秒級的時間戳轉換成時間格式:
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);