在Jmeter中用JAVA获取Rolling Date
Rolling Date_Weekly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 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); |
分类:
Java
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现