在Jmeter中用JAVA获取Rolling Date

系统 1580 0

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);




    

 

在Jmeter中用JAVA获取Rolling Date


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论