Last active
August 29, 2015 14:26
-
-
Save zhuhai/94b9faca1e48b00f2db5 to your computer and use it in GitHub Desktop.
获取两个指定日期间的所有日期
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<String> getDateList(String startDate,String endDate) throws ParseException{ | |
List<String> list = new ArrayList<String>(); | |
list.add(startDate); | |
Calendar calendar = Calendar.getInstance(); | |
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); | |
calendar.setTime(sdf.parse(startDate)); | |
boolean flag = true; | |
while(flag){ | |
calendar.add(Calendar.DAY_OF_MONTH, 1); | |
if(sdf.parse(endDate).compareTo(calendar.getTime())>=0){ | |
list.add(sdf.format(calendar.getTime())); | |
}else { | |
break; | |
} | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment