This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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".
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.
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: 88
posted
0
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: 32833
4
posted
0
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: 88
posted
0
The process done was simple. Let me see if I can get some other ideas. Thanks.