本文共 2177 字,大约阅读时间需要 7 分钟。
package com.test;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.concurrent.CountDownLatch;import org.apache.commons.lang3.time.DateFormatUtils;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4Cla***unner;@RunWith(SpringJUnit4Cla***unner.class) //使用junit4进行测试 @ContextConfiguration({"classpath*:/spring/conf/applicationContext-mvc.xml"}) //加载配置文件 public class Test { //并发数 private static final int threadNum = 2000; //倒计时数 发令枪 用于制造线程的并发执行 private static CountDownLatch cdl = new CountDownLatch(threadNum); @org.junit.Test public void test() { System.out.println("1"); for(int i = 0;i< threadNum;i++) { //new多个子线程 new Thread(new ThreadClass()).start(); //计数器-1 cdl.countDown(); } try { //主线程 等待 子线程执行完 等待 Thread.currentThread().join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //多线程执行类 public class ThreadClass implements Runnable{ @Override public void run() { try { //所有子线程在这里等待,当所有线程实例化后,停止等待 cdl.await(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } //执行业务方法 } } @org.junit.Test public void Run() { System.out.println("423"); } public static void main(String[] args) { System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd 00:00")); System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd 23:59")); Date date=new Date();//取时间 Calendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.add(calendar.DATE,-1);//把日期往后增加一天.整数往后推,负数往前移动 date=calendar.getTime(); //这个时间就是日期往后推一天的结果 SimpleDateFormat start = new SimpleDateFormat("yyyy-MM-dd 00:00"); String startDate = start.format(date); SimpleDateFormat end = new SimpleDateFormat("yyyy-MM-dd 23:59"); String endDate =end.format(date); System.out.println(startDate); System.out.println(endDate); }}
转载于:https://blog.51cto.com/hackerxian/2117140