java获取指定开始时间与结束时间之间的所有日期
人气:0import 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(); } }
运行结果:
您可能感兴趣的文章:
加载全部内容