• 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

Problem with day light savings in Simple Date Formatter

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have the following problem with Simple Date Formatter.

In my application, I will get the Europe time from Server as "3:00 PM"(for eg.,) in String format. which I will be parsing using the simple date formatter as below.



The date value is "03 Nov 2008, 7:30 00 000 PM IST". The diff is 4 1/2 Hrs. This is good till Oct 26th as the Day Light Saving was ON. But from 27th Oct, the diff between IST and BST is 5 1/2 hrs. But the above piece of code still gives me "03 Nov 2008, 7:30 00 000 PM IST". Instead it should give "03 Nov 2008, 8:30 00 000 PM IST".

Can someone help me in getting this right?

Thanks for the same. Please reply ASAP.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing Swing related here.
Moving ti JIG(B) where you will get better answers.

And please Ease Up.
[ November 03, 2008: Message edited by: Maneesh Godbole ]
 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Thanks for moving it to right forum :-)

The code part in the above post has some typo. Here is the correct code part.




And the result that I got is

****** PARSING USING SIMPLE DATE FORMAT ******
The Unparsed Europe Input Time is 3:00 PM
The After Parsing IST Time is Thu Jan 01 19:30:00 IST 1970
****** FORMATTING USING SIMPLE DATE FORMAT ******
The UNFormatted IST Time is Mon Nov 03 14:24:49 IST 2008
The Formatted EST Time is 8:54 AM


From above, the same SimpleDateFormat is used for parsing the string and formatting the date object.

When formatting the current date, the diff is 5 1/2 Hrs
When parsing the string, the diff is 4 1/2 Hrs.
 
Marshal
Posts: 79268
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just because the original date you are giving is in Winter, doesn't mean to say it is in GMT; we were 1 hour ahead of ourselves for the whole of that winter, so you will have to work out for GMT+1hour. I think your 4� hours are correct.
 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh. What I thought was, when i ask the Formatter to parse it. I give only "3:00 PM", but no date, month & year.

So we tried getting the current date and taking the date, month and year from there and appending it with the time i.e "3:00 PM" and ask the formatter to parse. It gave me correct 51/2 hrs. Please see the code below. Not sure if this is right approach.



The Output is:
The After Parsing IST Time is Mon Nov 03 20:30:00 IST 2008
 
Campbell Ritchie
Marshal
Posts: 79268
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks a bit convoluted, with repeated parsing and creating Strings, but it seems to give the correct answer.
 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The process done was simple. Let me see if I can get some other ideas. Thanks.
 
It runs on an internal combustion engine. This ad does not:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic