-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Java Date or Calendar adds default timezone info?
PostPosted: Sun Oct 05, 2008 2:19 pm 
Newbie

Joined: Thu May 26, 2005 6:31 pm
Posts: 19
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:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.