• 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

SQL dates, seconds since epoch and GMT/BST differences

 
Ranch Hand
Posts: 92
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for sharing, John.
 
reply
    Bookmark Topic Watch Topic
  • New Topic