我必须在特定日期范围之间为每个月的每一天创建表格(例如,2012-01-30至2013-04-30).我正在尝试使用三个for循环和DateTime isBefore方法来执行此操作,但是我的循环无限运行(尽管日期,月份和年份按其应有的方式递增).我在下面写的代码片段,
DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm");
DateTime startDate = dtf.parseDateTime(startDateTime);
DateTime endDate = dtf.parseDateTime(endDateTime);
try{
for(DateTime y=startDate;y.isBefore(endDate);y=y.plusYears(1)) {
for(DateTime month=startDate;startDate.isBefore(endDate);month=month.plusMonths(1)) {
for(DateTime date=startDate;startDate.isBefore(endDate);date=date.plusDays(1)){
String sqlStmt = "CREATE TABLE IF NOT EXISTS...
...
}
}
}
} catch (SQLException e) {
StackTraceElement stack = e.getStackTrace()[2];
}
Run Code Online (Sandbox Code Playgroud)
我的表是按照我想要的方式创建的,所以我正在尝试执行的sqlstmt没有问题,只是一旦遇到endDate,循环就不会终止.我是Java的新手,所以不太确定我在这里做错了什么.任何建议都会非常有用!!!
谢谢!