• 在Jmeter中用JAVA获取Rolling Date


    Rolling Date_Weekly

    import java.util.*;
    import java.text.SimpleDateFormat;
    import java.text.DateFormat;
    
    int oldY=2010;
    int oldM=10;
    int oldD=7;
    
    vars.put("oldDateWeekly",oldM+"/"+oldD+"/"+oldY);
    
    Calendar oldCal=Calendar.getInstance();
    oldCal.set(oldY,oldM-1,oldD);
    int oldDayOfWeek = oldCal.get(Calendar.DAY_OF_WEEK);
    System.out.println("The oldDate_Weekly is:"+oldM+"/"+oldD+"/"+oldY); 
    
    Calendar newCal=Calendar.getInstance();
    int newDayOfWeek =newCal.get(Calendar.DAY_OF_WEEK);
    int delta=oldDayOfWeek-newDayOfWeek;
    delta=delta<0 ? delta+7 : delta;
    newCal.add(Calendar.DATE,delta);
    
    /** 输出格式: 11/07/2013**/
    java.text.DateFormat format1 = new java.text.SimpleDateFormat("MM/dd/yyyy");
    cur=format1.format(newCal.getTime());
    System.out.println("The rollingDate_Weekly is:"+cur);
    vars.put("rollingDateWeekly",cur);
    

     Rolling Date_Month

    import java.util.*;
    import java.text.SimpleDateFormat;
    import java.text.DateFormat;
    
    int oldY=2010;
    int oldM=10;
    int oldD=7;
    
    vars.put("oldDateMonth",oldM+"/"+oldD+"/"+oldY);
    
    Calendar oldCal=Calendar.getInstance();
    oldCal.set(oldY,oldM-1,oldD);
    int oldDayOfMonth = oldCal.get(Calendar.DAY_OF_MONTH);
    System.out.println("The oldDate_Month is:"+oldM+"/"+oldD+"/"+oldY); 
    
    Calendar newCal=Calendar.getInstance();
    int newDayOfMonth =newCal.get(Calendar.DAY_OF_MONTH);
    int delta=oldDayOfMonth-newDayOfMonth;
    delta=delta<0 ? 1 : 0;
    newCal.add(Calendar.MONTH,delta);
    newCal.set(Calendar.DATE,oldD);
    
    /** 输出格式: 11/07/2013**/
    java.text.DateFormat format1 = new java.text.SimpleDateFormat("MM/dd/yyyy");
    cur=format1.format(newCal.getTime());
    System.out.println("The rollingDate_Month is:"+cur);
    vars.put("rollingDateMonth",cur);
    
    /** 输出格式: 20131107**/
    java.text.DateFormat format2 = new java.text.SimpleDateFormat("yyyyMMdd");
    cur2=format2.format(newCal.getTime());
    System.out.println("The rollingDate_Month is:"+cur2);
    vars.put("rollingDateMonth2",cur2);
    

     Rolling Date_Quater

    import java.util.*;
    import java.text.SimpleDateFormat;
    import java.text.DateFormat;
    
    int oldY=2013;
    int oldM=3;
    int oldD=20;
    
    vars.put("oldDateQuater",oldM+"/"+oldD+"/"+oldY);
    
    Calendar oldCal=Calendar.getInstance();
    oldCal.set(oldY,oldM-1,oldD);
    System.out.println("The oldDate_Quater is:"+oldM+"/"+oldD+"/"+oldY); 
    
    Calendar newCal=Calendar.getInstance();
    int newY = newCal.get(Calendar.YEAR);    //获取年
    int newM = newCal.get(Calendar.MONTH)+1;    //获取月
    int newD = newCal.get(Calendar.DAY_OF_MONTH);    //获取日
    System.out.println("11111newY newM is:"+newY+" "+newM);
    while ((newY>oldY) || (newY==oldY && newM>oldM) || (newY==oldY && newM==oldM && newD>oldD))
    {
          oldCal.add(Calendar.MONTH,3);
          oldY = oldCal.get(Calendar.YEAR);    //获取年
          oldM = oldCal.get(Calendar.MONTH)+1;    //获取月
    }
    
    /** 输出格式: 11/07/2013**/
    java.text.DateFormat format1 = new java.text.SimpleDateFormat("MM/dd/yyyy");
    cur=format1.format(oldCal.getTime());
    System.out.println("The rollingDate_Quater is:"+cur);
    vars.put("rollingDateQuater",cur);
    
    /** 输出格式: 20131107**/
    java.text.DateFormat format2 = new java.text.SimpleDateFormat("yyyyMMdd");
    cur2=format2.format(oldCal.getTime());
    System.out.println("The rollingDate_Quater is:"+cur2);
    vars.put("rollingDateQuater2",cur2);
    
    

     Rolling Date_Six Month

    import java.util.*;
    import java.text.SimpleDateFormat;
    import java.text.DateFormat;
    
    int oldY=2012;
    int oldM=10;
    int oldD=31;
    
    vars.put("oldDateSixMonth",oldM+"/"+oldD+"/"+oldY);
    
    Calendar oldCal=Calendar.getInstance();
    oldCal.set(oldY,oldM-1,oldD);
    System.out.println("The oldDate_SixMonth is:"+oldM+"/"+oldD+"/"+oldY); 
    
    Calendar newCal=Calendar.getInstance();
    int newY = newCal.get(Calendar.YEAR);    //获取年
    int newM = newCal.get(Calendar.MONTH)+1;    //获取月
    int newD = newCal.get(Calendar.DAY_OF_MONTH);    //获取日
    System.out.println("11111newY newM is:"+newY+" "+newM);
    while ((newY>oldY) || (newY==oldY && newM>oldM) || (newY==oldY && newM==oldM && newD>oldD))
    {
          oldCal.add(Calendar.MONTH,6);
          oldY = oldCal.get(Calendar.YEAR);    //获取年
          oldM = oldCal.get(Calendar.MONTH)+1;    //获取月
          System.out.println("oldY oldM is:"+oldY+" "+oldM);
    }
    
    /** 输出格式: 11/07/2013**/
    java.text.DateFormat format1 = new java.text.SimpleDateFormat("MM/dd/yyyy");
    cur=format1.format(oldCal.getTime());
    System.out.println("The rollingDate_SixMonth is:"+cur);
    vars.put("rollingDateSixMonth",cur);
    
    /** 输出格式: 20131107**/
    java.text.DateFormat format2 = new java.text.SimpleDateFormat("yyyyMMdd");
    cur2=format2.format(oldCal.getTime());
    System.out.println("The rollingDate_SixMonth is:"+cur2);
    vars.put("rollingDateSixMonth2",cur2);
    
    
  • 相关阅读:
    CSRF
    PHP XXE漏洞
    jumpserver安装与部署
    ELK
    docker pull下来的镜像放哪儿了?
    MobSF 框架安装使用部署
    加密流量分析
    Pόlya定理-学习笔记
    所有区间异或的和的 一个加强
    计算一个序列有多少个不同的01子序列
  • 原文地址:https://www.cnblogs.com/MasterMonkInTemple/p/3431477.html
Copyright © 2020-2023  润新知