File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Date, Calendar and TimeZones Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Date, Calendar and TimeZones" Watch "Date, Calendar and TimeZones" New topic
Author

Date, Calendar and TimeZones

Matt James
Greenhorn

Joined: Jan 28, 2004
Posts: 22
Hi

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.

Thanks in anticipation

Matt
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

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
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.

Everything seems a lot better now.

Cheers

Matt
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Date, Calendar and TimeZones
 
Similar Threads
Java Date formatting problem
Date Formatting
Handling a strange date format
Converting String to Date???
DST issue with GregorianCalendar