Date and timezones [message #936558] |
Mon, 08 October 2012 05:26 |
Rami D. Messages: 14 Registered: August 2012 |
Junior Member |
|
|
Hello,
i have a feature label of type EDate which a user can set via a dialog in the properties view. The dialog also contains besides a datepicker and spinners for date and time also a combo box to set the timezone. Therefor a GregorianCalendar is instantiated with the user's selections and a Date object is returned by the method gc.getTime(). My problem is that the timezone setting is ignored, probably because java.util.Date doesn't consider timezones (although there is a deprecated method getTimezoneOffset()).No matter what I'm doing it always shows +0200 as the timezone value. If I deactivate the dialog and modify the timezone value directly in the properties view it works of course, but the user shouldn't take care of the format (yyyy-MM-dd'T'HH:mm:ss'.'SSSZ). Through debugging i found out that the convertion from Date to String is done somewhere in the EMF framework using (Simple)DateFormat. The question is do I have to implement this myself and if so,where and how can this be done?
Regards,
Rami
[Updated on: Mon, 08 October 2012 05:32] Report message to a moderator
|
|
|
Re: Date and timezones [message #936645 is a reply to message #936558] |
Mon, 08 October 2012 07:24 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Rami,
Comments below.
On 08/10/2012 7:26 AM, Rami D. wrote:
> Hello,
>
> i have a feature label of type EDate which a user can set via a dialog
> in the properties view. The dialog also contains besides a datepicker
> and spinners for date and time also a combo box to set the timezone.
> Therefor a GregorianCalendar is instantiated with the user's
> selections and a Date object is returned with the method gc.getTime().
> My problem is that the timezone setting is ignored, probably because
> java.util.Date doesn't consider timezones (although there is a
> deprecated method getTimezoneOffset()).
What do you mean by ignored? In the end, a Date is just a long value.
It doesn't record any timezone information...
> No matter what I'm doing it always shows +0200 as the timezone value.
You're expecting it to preserve the timezone? You can see that
GregorianCalendar.getTime() is just a long... This will always be
normalized to be your computer's time zone.
> If I deactivate the dialog and modify the timezone value directly in
> the properties view it works of cause, but the user shouldn't take
> care of the format (yyyy-MM-dd'T'HH:mm:ss'.'SSSZ).
Even here, I expect the timezone is not preserved. It will always be
normalized to your time zone.
> Through debugging i found out that the convertion from Date to String
> is done somewhere in the EMF framework using (Simple)DateFormat. The
> question is do I have to implement this myself and if so,where and how
> can this be done?
I think it's more of a question of expectations. I don't think you can
expect java.util.Date to preserve timezone information. It sounds
like you want something like javax.xml.datatype.XMLGregorianCalendar
which is supported by the DataTime data type in the XMLTypePackage.
>
> Regards,
> Rami
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03022 seconds