时间:2020-11-23 12:14:55 | 栏目:JAVA代码 | 点击:次
本文实例为大家分享了java获取指定开始时间与结束时间之间的所有日期的具体代码,供大家参考,具体内容如下
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(); } }
运行结果: