jmeter获取当前时间,转化成yyyy-MM-dd

 

 

 beanshell脚本如下:

 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; 
try{
    Date date =new Date();  //获取当前时间
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");//把当前时间转成yyyy形式
    String nowDate = sf.format(date);//得到当前时间的yyyy-mm-dd形式
    log.info("------nowDate------"+ nowDate);
    String endTimeNowDate = nowDate+" 23:59:59";
    log.info("+++++++拼接后的结束时间++++++++endTimeNowDate:"+ endTimeNowDate);
    vars.put("endTimeNowDate",endTimeNowDate);

    Calendar cal = Calendar.getInstance();
    cal.setTime(sf.parse(nowDate));
    long nowDate1 = cal.getTimeInMillis();
    vars.put("nowDate1",nowDate1.toString());
       //当前时间,把nowDate1放在结束时间;
       
    cal.add(Calendar.DAY_OF_YEAR,+1);    //当前时间+1天
    String orderDate = sf.format(cal.getTime());
    sfDate =  sf.parse(orderDate);
    cal.setTime(sfDate);
    long nowDate2 = cal.getTimeInMillis();
    vars.put("nowDate2",nowDate2.toString());
  
     /*******************************************************/   
    cal.add(Calendar.DAY_OF_YEAR,-8);   //当前时间-8天
    String senderDate = sf.format(cal.getTime());
    log.info(">>>>>>>>>>>>>>>>>>>>+senderDate:"+ senderDate);
    String  startTimeSenderDate= senderDate+" 00:00:00" ; 
    log.info(">>>>>>>>>>>拼接后的开始时间>>>>>>>>>+startTimeSenderDate:"+ startTimeSenderDate);
        vars.put("startTimeSenderDate",startTimeSenderDate);
    /*******************************************************/
    
    sfDate1 =  sf.parse(senderDate);
    cal.setTime(sfDate1);
    long endDate = cal.getTimeInMillis();
    vars.put("endDate",endDate.toString());
    //当前时间-6天 ,把endDate,放在开始时间      
}
catch(Exception e){
 log.info("抛出异常");  
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值