简体   繁体   中英

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.printStackTrace();
    }

( 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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM