PDA

View Full Version : Showing local time given UTC using Datafield



boardtc
17 Jun 2010, 8:57 AM
All our dates are stored as UTC in the database and we want to show them as local times depending on the timezone of the client machine.

Currently any date columns to show in a grid get set as follows:

com.extjs.gxt.ui.client.data.Datafield.setType(Date.class);
com.extjs.gxt.ui.client.data.Datafield.setFormat("yyyy-MM-dd HH:mm:ss.S");

With a SimpleDateFormat one can do something like:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S.'Z'");
sdf.setTimeZone(TimeZone.getDefault());

Will setFormat("yyyy-MM-dd HH:mm:ss.S'Z'") suffice? I'm wondering if I can deal with timezones at the Datafield level rather than in a render method?

I may also need to look at localizing the date as well. I have seen some references to using CultureInfo.CurrentCulture, but again am wondering can this be done at the Datafield level.

Any advice appreciated.

boardtc
18 Jun 2010, 4:12 AM
Moving post to GXT forum, sorry for confusion.