开发者

Playframework inserting wrong date in database

I'm having a strage problem. In my form I'm using the jQuery datetime picker. This generates a string like 05/23/2011 07:33.

In my java code i'm using DateFormat to create a date object out of that string:

    System.out.println(execute);
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy kk:mm");
    Date date = null;
    try {
        date = df.parse(execute);
    } catch (ParseException e) {
        e.printS开发者_如何学编程tackTrace();
    }

(execute is the string which contains the date). In the console, println() is showing the right date. And I'm using that date object when I write an instane of a Model to the database. But once I call the save() function (from the model), the timestamp that is inserted in the database is completely wrong.

In this case it is: 2012-11-05 07:33:00 The time is correct, but the date is sometimes more than a year off!

Any ideas what's causing this?


Are you sure about your date format "dd/MM/yyyy kk:mm"?
You get day/month/year but in "05/23/2011 07:33" it's month/day/year, isn't it?


I had a similar issue as the jQuery date time picker was using a different formatting for the date than my Java code, and that changed the date to be saved. Check it :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜