I have a method where I am passing in a string and getting a Date object back. Because of DST or TimeZones I am getting odd results. I pass in 30/06/2006 23:30:00 and use SimpleDateFormat to parse it (using TimeZone.getTimeZone("GMT") as the timezone), and the date that I get out is Sat Jul 01 00:30:00 BST 2006.
Is there a way to get back a date object that is exactly equal to the string that I pass in without any DST alterations.
Well, no. But that's only because a Date is a Date and a String is a String and it doesn't make sense to compare them.
However if you want to format a date in GMT, then you can use a SimpleDateFormat with its time zone set to GMT to do that. (Just call the format(Date) method.)
What you see, I expect, is the result of calling the Date object's toString() method. This formats the date in your system's default timezone, which would be BST.
Matt James
Greenhorn
Joined: Jan 28, 2004
Posts: 22
posted
0
Paul
Many thanks for that. I was confusing myself by putting the Date to System.out.println to check what it was being set to, which of course will use the toString - whoops.