cancel
Showing results for 
Search instead for 
Did you mean: 

How to change TimeZone format

Former Member
0 Kudos

Hi all,

I am having some problem to format timezone . I have taken the sample code with formats time.

Code:

-


public void AllTimeZones( java.util.Locale locale )

{

//@@begin AllTimeZones()

IWDMessageManager msgMgr=wdComponentAPI.getMessageManager();

Hashtable timeZonesIds;

Vector sortedIds;

Locale _locale = (locale==null)?Locale.getDefault():locale;

String[] ids = TimeZone.getAvailableIDs();

timeZonesIds = new Hashtable(ids.length);

sortedIds = new Vector(ids.length);

final String format = "GMT{0}{1,number,00}:{2,number,00} () ";

Object[] arguments = new Object[5];

String id = null;

for ( int i = 0; i < ids.length; i++ ) {

// get offset in minutes sec from UTC

id = ids<i>;

int offset = TimeZone.getTimeZone(id).getRawOffset() / (60*1000);

int hours = Math.abs(offset / 60);

int mins = Math.abs(offset % 60);

arguments[0] = offset < 0 ? "-" : "+";

arguments[1] = new Integer(hours);

arguments[2] = new Integer(mins);

arguments[3] = id;

arguments[4] = TimeZone.getTimeZone(id).getDisplayName(_locale);

//msgMgr.reportSuccess("Time zone ids : " +timeZonesIds.toString());

timeZonesIds.put(ids<i>, MessageFormat.format(format, arguments));

sortedIds.add(ids<i>);

}

//@@end

}

-


I am writing the following code to see in dropdownkey on clicking a button action, also display as messages

IWDDropDownByKey sel_lng = (IWDDropDownByKey)view.getElement("lang_DropDownByKey");

String key = sel_lng.getId();

msgMgr.reportSuccess("Selected Language :"+ key);

-


Time zone ids : {Etc/GMT12=GMT-12:00 (Etc/GMT12) GMT-12:00}

Time zone ids : {Etc/GMT12=GMT-12:00 (Etc/GMT12) GMT-12:00, Etc/GMT11=GMT-11:00 (Etc/GMT11) GMT-11:00}

Time zone ids : {Etc/GMT12=GMT-12:00 (Etc/GMT12) GMT-12:00, Etc/GMT11=GMT-11:00 (Etc/GMT11) GMT-11:00, MIT=GMT-11:00 (MIT) West Samoa Time}

But I want the result as bellow...

Time zone ids : (Etc/GMT+12) GMT-12:00}

Time zone ids : (Etc/GMT+11) GMT-11:00}

Time zone ids : (MIT) West Samoa Time}

Can any one help me.

I promise to award points to the right solution. Thank you in advance.

Regards

Maruti

chandra-s@mailcity.com

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

hi

good

go through this links

http://www.sap.com/usa/industries/retail/pdf/BWP_SID_Globalization_Requirements.pdf

try this also

TimeZone myTZ = TimeZone.getTimeZone("GMT-5");

DateFormat df = DateFormat.getDateTimeInstance();

df.setTimeZone(myTZ);

String date_time = df.format(Calendar.getInstance().getTime());

thanks

mrutyun^

Former Member
0 Kudos

Hi,

Change your format pattern to


final String format = "({3}) {4}";

Also the code that you have listed has some errors, but I guess they are just typos.

Regards,

Satyajit.