Set the TimeZone to use TimeItem value in client side code

Hello,

For our application, we need a way to set the TimeZone for all the client side application. We want all smartGWT items use local GMT.

Actually, we use a TimeItem to get an hour but the javascript Date object returned is in GMT+0 instead of client GMT.

It’s not a problem when we use the Date object in the server side but we need to use it in our client side code to call a BIRT report by url with this time value in param.

However, Calendar and others java commons time manage classes can’t be used in client side code.

I try to use Date.getTimezoneOffset() to calcul the good value but it does’nt satify me, I don’t want to modify my code after each TimeItem.getValue().

Any ideas ?

(excuse my horrible frenglish, the day was long … I hope it’s understandable)

Not really following - if all you need is to turn the date into an appropriate String for use in a URL, the APIs on Date should allow you to do this.

Ok, code sample :

I make a form with two TimeItem Object :

		startTime = new TimeItem();

		endTime = new TimeItem();

The user enters 14:00 and 22:00, he is in GMT+2

The following code allows me to get the values :

           submitItem.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				if (form.validate()) {
                                        DateTimeFormat dateFormatterTime = DateTimeFormat.getFormat("HH:mm:ss");

					String timeStart = dateFormatterTime
							.format((Date) startTime.getValue());
					
					String timeEnd = dateFormatterTime
							.format((Date) endTime.getValue());
                                }
                         }
           }

The values are :

timeStart = 12:00:00
timeEnd = 20:00:00

What are my options to get the values enter by the user ?

I have different forms with TimeItem in my application. Sometimes I need String, sometimes Date object and I don’t want to write code for each case. So I would like a global solution to set the local time zone once for all the application. Is It possible ?

Thank you for your help.

Ok I discussed this issue with my team and it appears I miss-understand the real problem.

So forget my old posts, The problem is :

When we use TimeItem to display a time in order to modify it, the value displayed in the TimeItem is in GMT+0.

My question is always the same, I need smartGWT use local time zone to display Date object. I hope my need is clearer now.

You can do this with Time.setDefaultDisplayTimezone() - this is a SmartClient API not yet exposed in SmartGWT, so you’ll need to call it via JSNI.

Added DateUtil.setDefaultDisplayTimezone(offset) to SVN.

Sanjiv

Thanks for your help :slight_smile: