on 02-07-2008 7:58 PM
Hi,
I have to get the time from a timezone that is not the current timezone. So, I do the following:
TimeZone timeZone = TimeZone.getTimeZone("America/La_Paz");
Calendar calendar = Calendar.getInstance(timeZone);
long longTime = calendar.getTime().getTime();
Time time = new Time(longTime);
If I print the time using:
wdComponentAPI.getMessageManager().reportSuccess(time.toString());
the output is right, but when I set this same Time instance to a context element (with Time type) that is linked to an InputField, that InputField shows me the time of the current TimeZone.
Any Ideas?
Thanks in advance
Michel Cabral
Edited by: Michel Amaral on Feb 7, 2008 8:58 PM
Michel-
Introduce this method in your -others- section of your controller:
private Time getDateInTimeZone(Date currentDate, String timeZoneId)
{
TimeZone timeZone = TimeZone.getTimeZone(timeZoneId);
Calendar aCal = new GregorianCalendar(TimeZone.getTimeZone(timeZoneId));
aCal.setTimeInMillis(currentDate.getTime());
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, aCal.get(Calendar.YEAR));
cal.set(Calendar.MONTH, aCal.get(Calendar.MONTH));
cal.set(Calendar.DAY_OF_MONTH, aCal.get(Calendar.DAY_OF_MONTH));
cal.set(Calendar.HOUR_OF_DAY, aCal.get(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, aCal.get(Calendar.MINUTE));
cal.set(Calendar.SECOND, aCal.get(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, aCal.get(Calendar.MILLISECOND));
return new Time(cal.getTimeInMillis());
}
Usage:
Time t = getDateInTimeZone(new Date(), "PST");
Create an attribute of type time in your context and set it to this value.
Cheers-
Atul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
declare a context attribute of type string and assign time.toString() to it and assign this context to the input field
xxxxxxxxxxxxxxx
Edited by: Armin Reichert on Feb 18, 2008 7:32 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.