I am using hibernate and mysql with my java based web application.
Since most of my users are in the same timezone (same as my tomcat and mysql), I tried to implement the system simple and not to worry about timezone issue.
In my schema, all date column is defined as: DATETIME NOT NULL
In my code, I set the date manually, e.g. setCreated(new Date());
In my data access layer, store the object (with created) using hibernate
In my presentation layer, I retrieve the object using hibernate and present it directly.
Everything works perfectly for about a year. Now, I tried to implement a new feature, and hit the following problem:
Object Game, has two fields, startdate and enddate. Both are input by user. Since enddate should be inclusive. I need to add one more day to it and store it into the database. Here's my code:
// enddate is converted form SimpleDateFormat
setEnddate(Date enddate) {
this.endDate = new Date(endDate.getTime() + 24*3600*1000 - 1);
// Calendar c = Calendar.getInstance();
// c.setTime(endDate);
// c.add(Calendar.DAY_OF_MONTH, 1);
// this.endDate = c.getTime();
}
user input: startdate 2008-10-08, enddate 2008-10-18
in jsp output: startdate: 2008-10-08 00:00:00.0 enddate: Sun Oct 19 23:59:58 CST 2008
in the database, it shows as: 2008-10-08 00:00:00 | 2008-10-18 23:59:59
which part cause the problem? seems the new Date or Calendar function add a default timezone info into the date. Is there a way to eliminate it?
My ideal output should be: startdate: 2008-10-08 00:00:00.0 enddate: 2008-10-18 23:59:59
where's the CST part coming from and it is off by one day. Please help.
Code:
Code:
Code:
Code: