转自:https://www.jb51.net/article/162132.htm
本文实例为大家分享了java获取指定开始时间与结束时间之间的所有日期的具体代码,供大家参考,具体内容如下
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import java.text.SimpleDateFormat;import java.util.Calendar; public class TimerTest { public static void main(String[] args) throws Exception { String beginDate = "2016-07-16";//开始时间 String endDate = "2016-07-25";//结束时间 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.setTime(sdf.parse(beginDate)); for (long d = cal.getTimeInMillis(); d <= sdf.parse(endDate).getTime(); d = get_D_Plaus_1(cal)) { System.out.println(sdf.format(d)); } } public static long get_D_Plaus_1(Calendar c) { c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + 1); return c.getTimeInMillis(); }} |
运行结果:


浙公网安备 33010602011771号