Hi I have a small problem with seting TimeZone. in my apllication i have a date value as string , i need to parse it as Date object, and setting default timezone as PST, then if i parsed that string it is automatically converted into IST with different
here if i print the date iam getting like 05/19/2008 04:33 AM (IST) but it has to show same except timezone as PST after parsing the string using parse()
the output iam getting like Mon May 19 08:33:00 EDT 2008
but it is taking input as IST and setting to EDT as some time difference but what i need is it has to take as PST what i had given in string and if i change timezone as EST it has to show 3 hours difference as well as EST..
appriciate if any ideas..
the output value is :
Mon May 19 15:03:00 IST 2008
but i need :
05/19/2008 04:33 AM (EST)";
can you please let me know how can i do this.. appriciate if any ideas..
[ May 20, 2008: Message edited by: Naresh Talluri ]
One problem I see here is that no one uses PST or EST in May. It should be PDT or EDT - Pacific Daylight Time or Eastern Daylight Time. Whoever managed to put a PST on the original time there is probably mistaken, and should be ignored. (Or flogged.) This also appies to whoever is telling you that you "need" the output to be in EST. Not in May you don't. I would probably remove the final five characters from the String before parsing it, to avoid confusing Java's TimeZone class with a nonsense time zone indicator.
Also, three-letter time zones are not recommended for looking up TimeZone values. (Read the API for that class.) Unfortunately, Sun doesn't do a good job of documenting what your alternatives are. I recommend:
As for "I need the first format with the second time", I'm not sure what you mean. Can you show exactly what you think the output should look like?
I recommend you not use TimeZone.setDefault(), since you need two different time zones here (besides IST where you are presumably located). Instead call setTimeZone() on two different DateFormat objects - one for Pacific time, and one for Eastern. Use parse() with one, and format() with the other.
"I'm not back." - Bill Harding, Twister
posted 11 years ago
Hi jim thanks for your explanation but here if i used the code which i had given , it is not setting timezone properly, but if set using setTimeZone(TimeZone.getDefault()); it is able to set timezone.
the thing is if i set timezone to SimpleDateFormat it is working fine
here is the sample code...
and can you please let me know why we dont use setTimeZone(TimeZone.getDefault());