jQuery in Action, 2nd edition
The moose likes Beginning Java and the fly likes Calendar Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Calendar" Watch "Calendar" New topic
Author

Calendar

Zsuzsa Pocsai
Greenhorn

Joined: Nov 18, 2002
Posts: 11
I need help please,
I have got an object which has a creation date time parameter which is of type calendar. When I save the object to the database it is 14pm 34 sec. When I read it back it is always one hour behind I have no idea why. I have managed to locate that it goes wrong when I put the Date opject into the Calendars consturctor. The code is the following. Can anyone please tell me what is wrong with it? Thank you

private void getDateTime(String columnName, ResultSet rs, Calendar calendar) throws IntException
{
java.sql.Date date;
java.sql.Time time;
java.sql.Date datetime;
long longTime;
try {
date = rs.getDate(columnName);
time = rs.getTime(columnName);
System.out.println(time.getHours());
System.out.println(time.getMinutes());
if (date != null)
{
longTime = date.getTime();
if (time != null)
longTime += time.getTime();
longTime = date.getTime() + time.getTime();
System.out.println(time.getTime());
datetime = new java.sql.Date(longTime);
int offset = datetime.getTimezoneOffset();
//System.out.println(datetime.getHours());
//System.out.println(datetime.getMinutes());
calendar.setTime(datetime);
}
else
{
// Zero the date
setZeroDate(calendar);
}
}
catch (SQLException sqle)
{ "Error obtaining Oracle Date and Time. " + sqle.toString();
}
David Mason
Ranch Hand

Joined: Jan 21, 2002
Posts: 58

Is this a Daylight Saving Time effect ?
You say that it goes wrong when you instantiate the calendar. Is Calendar converting the absolute time that is held in the Date object into the time in your current time zone, including your current Daylight savings settings? Are you using the locale version of the constructor ?
Have you reverted to UCT settings and tried again?
Hope this helps
DBM
 
IntelliJ Java IDE
 
subject: Calendar
 
Threads others viewed
SQL dates, seconds since epoch and GMT/BST differences
Converting from GMT to Local Timezone using two seperate fields (date & time).
Date/Timestamp
Woa! Why does Date/Calendar do this?
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Opti onal fature not implem
MyEclipse, The Clear Choice