Calendar时间工具类

阅读更多
 SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");  
		
		//昨日
		String stratDate1 = null,endDate1 = null;
		Calendar c4 = Calendar.getInstance();
		c4.add(Calendar.DATE, -1);
		stratDate1 = format.format(c4.getTime());
		endDate1 = format.format(c4.getTime());
		log.info("##########【昨日】"+stratDate1+"||"+endDate1);
		
		//上周
		String stratDate2 = null,endDate2 = null;
		Calendar c3 = Calendar.getInstance();
		c3.add(Calendar.DATE, -1*7);
		c3.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
		stratDate2 = format.format(c3.getTime());
		c3.add(Calendar.DATE, 6);
		endDate2 = format.format(c3.getTime());
		log.info("##########【上周】"+stratDate2+"||"+endDate2);
		
		//上月
		String stratDate3 = null,endDate3 = null;
		Calendar c1 = Calendar.getInstance();      
		c1.set(Calendar.DAY_OF_MONTH,1);
		c1.add(Calendar.MONTH, -1);
		stratDate3 = format.format(c1.getTime());  
		
		Calendar c2 = Calendar.getInstance();      
		c2.set(Calendar.DAY_OF_MONTH, 
		c2.getActualMaximum(Calendar.DAY_OF_MONTH));    
		c2.add(Calendar.MONTH, -1);
		endDate3 = format.format(c2.getTime());  
		log.info("##########【上周】"+stratDate3+"||"+endDate3);

 

你可能感兴趣的:(Calendar时间工具类)