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