日历更改日期

时间:2019-04-30 15:10:26

标签: java calendar

日历正在更改从数据库加载的日期

    // 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 个答案:

答案 0 :(得分:0)

我将所有语句更改为getDate()而不是getString(),问题消失了。看来该应用程序不喜欢解析从数据库中提取的日期,因此我只是从数据库中将其作为Date而不是String进行了检索,从而无需解析检索到的数据。