日历更改日期

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


    // 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));


    }


临摹微笑
浏览 122回答 1
1回答

斯蒂芬大帝

我将所有语句更改为 getDate() 而不是 getString() 并且问题消失了。似乎该应用程序不喜欢解析从数据库中提取的日期,所以我只是从数据库中将其作为日期而不是字符串检索,从而无需解析检索到的数据。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java