项目用到,所以就写了一个,没啥好说的,直接贴代码:


/**
	 * 
	 * countDateAndSet:取时间集合最大的时间和最小的时间
	 * 
	 * @param dateList
	 * @return
	 * @throws ParseException String[]
	 */
	public String[] countDateAndSet(List<String> dateList) throws ParseException{
		
		if(dateList.size() < 2){
			return null;
		}
		String[] dateString = new String[2];
				
		Calendar calendar1 = Calendar.getInstance();  
		
		Calendar calendar2 = Calendar.getInstance();    
        
		List<Long> timeMillis = new ArrayList<Long>();
		for (String string : dateList) {
			calendar1.setTime(DateUtil.convertStringToDate(string,DateUtil.TIMEF_FORMAT));
			timeMillis.add(calendar1.getTimeInMillis());
		}
		
		calendar2.setTimeInMillis(Collections.max(timeMillis));
		dateString[0] = DateUtil.convertDateToString(calendar2.getTime(), DateUtil.TIMEF_FORMAT);
		
		calendar2.setTimeInMillis(Collections.min(timeMillis));
		dateString[1] = DateUtil.convertDateToString(calendar2.getTime(), DateUtil.TIMEF_FORMAT);
		
		return dateString;
	}


欢迎留言