File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Problem with day light savings in Simple Date Formatter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with day light savings in Simple Date Formatter" Watch "Problem with day light savings in Simple Date Formatter" New topic
Author

Problem with day light savings in Simple Date Formatter

Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 89
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.


Karthick D V
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

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 ]

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 89
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

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Feb 23, 2008
Posts: 89
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

Joined: Oct 13, 2005
Posts: 40052
    
  28
It looks a bit convoluted, with repeated parsing and creating Strings, but it seems to give the correct answer.
Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 89


The process done was simple. Let me see if I can get some other ideas. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with day light savings in Simple Date Formatter