In fact I'm facing a similar problem.
I don't know if this is exactly what the person who started this thread wanted to know.
Let's try to talk in a rigorous way.
A date object (basically a wrapper for a long timestamp) identifies a concrete moment in time and it's absolutely time-zone independent (a date object, strictly speaking, has no time zone). The reason to say it's GMT it's just anecdotic, because the epoch, on which timestamps are based, is defined as a GMT date (but the same epoch could be expressed in any other time zone and everything would work exactly the same).
So, yes, a Date object should never be "converted"........ assuming it was right in the first place.
Suppose you have a web application used by people from all around the globe.
When they write a date/time, they write it in their own timezone. It's not unusual that the framework you are developing on cannot determine the right timezone for the user and interprets the date/time entered by the user in its own default timezone, thus generating a wrong timestamp (a wrong Date object). Once this wrong timestamp arrives to your application, if your application knows the actual timezone of the user, you definitely want to fix the timestamp to represent the real moment in time the user meant when he wrote the date/time.
And this is where you get into trouble. You can (or may be you can't) bypass Date generation by the framework and "manually" parse the string with date/time info entered by the user and have a right Date object generated in the first place. But sounds more straightforward to let the framework do the wrong thing and then just centralize in one point of the application the "fix" of all received (or sent back to the user) Dates.
The question, for me, is: is there a simple, straightforward way to fix a wrong timestamp?
I tried to create a Calendar instance with the application default timezone, set the "wrong" Date, and then set the user's timezone, but the calendar does not touch the timestamp you set. Instead it will just show different values for the different fields when you query it.
So, the only way I find is a bit tedious:
- Create a Calendar object with default timezone (cal1).
- Set the wrong Date value
- Create a second Calendar object with user timezone (cal2).
- Get every date/time field from cal1 (except redundant ones). These should be exactly the ones the user entered, as they are being generated using the same timezone originally used to interpret the date/time string from the user.
- Set all these values in cal2. Calendar internal timestamp will be calculated this time using the right timezone.
- Get the fixed Date object from cal2.
I think this would work, but does anybody know about a more straightforward way to do it, or a library that already implemented this?
Thanks