• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

millenium bug returns!

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
James Hewitt
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Superb. The k's did it. Thanks very much for that.
James
 
James Hewitt
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, k's are weird. H's do the trick much better
Thanks again,
James
 
reply
    Bookmark Topic Watch Topic
  • New Topic