cancel
Showing results for 
Search instead for 
Did you mean: 

Get date from another TimeZone

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

ThatSAPGuy
Advisor
Advisor
0 Kudos

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

Answers (1)

Answers (1)

Former Member
0 Kudos

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