*
The moose likes Servlets and the fly likes millenium bug returns! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "millenium bug returns!" Watch "millenium bug returns!" New topic
Author

millenium bug returns!

James Hewitt
Greenhorn

Joined: Jul 09, 2001
Posts: 27
Getting an interesting problem. I am retrieving a time from a database, stored in the form "Thu Jul 12 12:13:19 GMT+01:00 2001". In order to get it into my servlet, I import it as a string. Then, because I want to perform calculations on it, I convert it to date form. To do this, I:
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd hh:mm:ss zzzzzzzzzz yyyy");
and then,
java.util.Date d = sdf.parse(E);
where E is the string containing the date. This works perfectly for all times and dates with the exception of when the hour is "12" So, for example,
"Thu Jul 12 12:13:19 GMT+01:00 2001"
in the database, once imported and parsed is returned as:
"Thu Jul 12 00:13:19 GMT+01:00 2001"
That is, it interprets both the hours 00 and 12 in the database to be 00, midnight.
Any ideas how I get around this?
Thanks,
James
Rehan Malik
Ranch Hand

Joined: Jul 09, 2001
Posts: 76
According to the API for SimpleDateFormat, here are the possible formats:
Symbol Meaning Presentation Example
------ ------- ------------ -------
G era designator (Text) AD
y year (Number) 1996
M month in year (Text & Number) July & 07
d day in month (Number) 10
h hour in am/pm (1~12) (Number) 12
H hour in day (0~23) (Number) 0
m minute in hour (Number) 30
s second in minute (Number) 55
S millisecond (Number) 978
E day in week (Text) Tuesday
D day in year (Number) 189
F day of week in month (Number) 2 (2nd Wed in July)
w week in year (Number) 27
W week in month (Number) 2
a am/pm marker (Text) PM
k hour in day (1~24) (Number) 24
K hour in am/pm (0~11) (Number) 0
z time zone (Text) Pacific Standard Time
' escape for text (Delimiter)
'' single quote (Literal) '

Now, where you have "hh" for the hours, are you sure you should be using lowercase h's or uppercase? It would probably depend on how your database is configured. If your database will show the military time then use the capital 'h', otherwise, the lowercase should work.
So here are the possible suggestions that i can think of:
1. Use 'HH' instead of 'hh' // Depending on implementation
2. Use 'kk' instead of 'hh' // Depending on implementation
3. Use 'KK' instead of 'hh' // Depending on implementation
Originally posted by James Hewitt:
Getting an interesting problem. I am retrieving a time from a database, stored in the form "Thu Jul 12 12:13:19 GMT+01:00 2001". In order to get it into my servlet, I import it as a string. Then, because I want to perform calculations on it, I convert it to date form. To do this, I:
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd hh:mm:ss zzzzzzzzzz yyyy");
and then,
java.util.Date d = sdf.parse(E);
where E is the string containing the date. This works perfectly for all times and dates with the exception of when the hour is "12" So, for example,
"Thu Jul 12 12:13:19 GMT+01:00 2001"
in the database, once imported and parsed is returned as:
"Thu Jul 12 00:13:19 GMT+01:00 2001"
That is, it interprets both the hours 00 and 12 in the database to be 00, midnight.
Any ideas how I get around this?
Thanks,
James


Rehan Malik
James Hewitt
Greenhorn

Joined: Jul 09, 2001
Posts: 27
Superb. The k's did it. Thanks very much for that.
James
James Hewitt
Greenhorn

Joined: Jul 09, 2001
Posts: 27
Actually, k's are weird. H's do the trick much better
Thanks again,
James
 
Don't get me started about those stupid light bulbs.
 
subject: millenium bug returns!