import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Todate {
public static void main(String[] args) throws ParseException {
Calendar dayc1 = new GregorianCalendar();
Calendar dayc2 = new GregorianCalendar();
DateFormat df = new SimpleDateFormat("yy-MM-dd");
Date daystart = df.parse("17-1-1"); //按照yyyy-MM-dd格式转换为日期
Date dayend = df.parse("17-12-31");
dayc1.setTime(daystart); //设置calendar的日期
dayc2.setTime(dayend);
for (; dayc1.compareTo(dayc2) <= 0;) { //dayc1在dayc2之前就循环
System.out.println("PARTITION p"+
dayc1.get(Calendar.YEAR)+dayc1.get(Calendar.MONTH)+dayc1.get(Calendar.DATE)+" VALUES LESS THAN (TO_DAYS('"
+dayc1.get(Calendar.YEAR)+"-"+dayc1.get(Calendar.MONTH) +"-"+ dayc1.get(Calendar.DATE)+"')),"); //打印年月日
dayc1.add(Calendar.DAY_OF_YEAR, 1); //加1天
}
}
}
java 从开始时间到结束时间遍历一年所有时间
最新推荐文章于 2024-07-20 03:00:21 发布