Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with day light savings in Simple Date Formatter

 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Campbell Ritchie
Sheriff
Posts: 48409
56
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 48409
56
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator


The process done was simple. Let me see if I can get some other ideas. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic