This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL dates, seconds since epoch and GMT/BST differences

 
John McParland
Ranch Hand
Posts: 92
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
John McParland
Ranch Hand
Posts: 92
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2602
13
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for sharing, John.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic