Jmeter-获取当天00:00的时间戳

//【1】当前凌晨时间戳

long
nowTime =System.currentTimeMillis(); long todayStartTime =nowTime - ((nowTime + TimeZone.getDefault().getRawOffset()) % (24 * 60 * 60 * 1000L)); vars.put("beginTime",String.valueOf(todayStartTime));

 


//【2】当前凌晨时间戳
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.*;
    //当天日期
    Date date = new Date();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String today = simpleDateFormat.format(date.getTime());

    //1、当天凌晨(毫秒)
    long daytime1 = simpleDateFormat.parse(today).getTime();
    vars.put("beginTime",String.valueOf(daytime1));

 

 

 


//【3】当前凌晨时间戳

long
now = System.currentTimeMillis() / 1000l; long daySecond = 60 * 60 * 24; long dayTime4 = (now - (now + 8 * 3600) % daySecond) * 1000; vars.put("beginTime",String.valueOf(dayTime4));

 

 

//【4】当前凌晨时间戳

Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); long daytime3 = c.getTimeInMillis(); vars.put("beginTime",String.valueOf(daytime3));

  //获取当天23:59:59
  Calendar c = Calendar.getInstance();
  c.set(Calendar.HOUR_OF_DAY, 23);
  c.set(Calendar.MINUTE, 59);
  c.set(Calendar.SECOND, 59);
  c.set(Calendar.MILLISECOND, 0);
  long daytime31 = c.getTimeInMillis();
  vars.put("endTime",String.valueOf(daytime31));

 

 

posted @ 2021-08-19 14:49  youth0101  阅读(1001)  评论(0编辑  收藏  举报