zoukankan      html  css  js  c++  java
  • 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); 
  • 相关阅读:
    在mac守护进程中启动一个新进程
    OBS源码解析(3)OBSApp类介绍
    缩略图预览mini库
    Web Sql database 本地数据库
    React入口详解
    网页全屏显示
    使用cheerio爬数据兼容gbk和utf8
    前端自动化grunt的使用
    Emmet 神一样的sublime text插件
    BFC(Block Formatting Context)理解
  • 原文地址:https://www.cnblogs.com/insane-Mr-Li/p/12743815.html
Copyright © 2011-2022 走看看