日历正在更改从数据库加载的日期 // resultset fetching database content results = tp.getProjectTasks(projID); Calendar cal = Calendar.getInstance(); int month, day, year, endMonth, endDay, endYear; while (results.next()) { month = Integer.parseInt(smf.format(smf.parse(results.getString(7)))); year = Integer.parseInt(syf.format(syf.parse(results.getString(7)))); day = Integer.parseInt(sdf.format(sdf.parse(results.getString(7)))); cal.set(year, month, day, 0, 0, 0); Date startWork = cal.getTime(); // date is fine here System.out.println("CAL:"+results.getString(8)); endMonth = Integer.parseInt(smf.format(smf.parse(results.getString(8)))); endYear = Integer.parseInt(syf.format(syf.parse(results.getString(8)))); endDay = Integer.parseInt(sdf.format(sdf.parse(results.getString(8)))); // dates have changed here System.out.println(endYear+":"+endMonth+":"+endDay); cal.set(endYear, endMonth, endDay, 0, 0, 0); //cal.set(2019, 10, 31, 0, 0, 0); Date endWork = cal.getTime(); // endWork has incorrect Dates taskModel.add(new TimelineEvent(new Task(results.getString(2), "images/timeline/mail.png", true), startWork, endWork)); }
1 回答
斯蒂芬大帝
TA贡献1827条经验 获得超8个赞
我将所有语句更改为 getDate() 而不是 getString() 并且问题消失了。似乎该应用程序不喜欢解析从数据库中提取的日期,所以我只是从数据库中将其作为日期而不是字符串检索,从而无需解析检索到的数据。
添加回答
举报
0/150
提交
取消