| Author |
SQL dates, seconds since epoch and GMT/BST differences
|
John McParland
Ranch Hand
Joined: May 11, 2009
Posts: 92
|
|
Hi all,
I've got some code which takes a date or a date/time combination in a String, parses it and creates SQL dates and times. However it seems to produce incorrect results based on GMT and BST differences;
Running on my machine (UK timezone, currently in BST), the testGMTDates fails!
I don't understand why this happens. I'm particularly perplexed that the testGMTDates puts the same date as the testGMTTimes in an earlier month! Any pointers?
Many thanks,
John
|
Passed: SCJP 6 (90%), SCJD 6
Other: Spring training, extensive Swing experience
|
 |
John McParland
Ranch Hand
Joined: May 11, 2009
Posts: 92
|
|
And within seconds of posting, I feel like a numpty as I can now see the issue (I'll say it's because explaining it to someone else helps clarify the issue);
From testGMTDates;
From testGMTTimes;
The month (6th character of the string) is wrong in dateStr / testGMTDates.
|
 |
John McParland
Ranch Hand
Joined: May 11, 2009
Posts: 92
|
|
As a side note: do not use online epoch converters for Java code, they always gave different times for me depending on whether I was running on a UK or US machine due to GMT / BST differences.
Use Calendar#getInstance(), Calendar#set() and Calendar#getTimeInMillis() to get parsing against the real date / time.
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2350
|
|
|
Thank you for sharing, John.
|
OCUP UML fundamental
ITIL foundation
|
 |
 |
|
|
subject: SQL dates, seconds since epoch and GMT/BST differences
|
|
|