Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
New Developer
vsk
Posts: 15
Registered: ‎12-03-2009
My Device: Not Specified

ho to set timezone in blackberry

hi,

 

 

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("GMT-4"));
String timestamp = formatter.format(new Date());
System.out.println(timestamp);

 

in java, i used the following to code to set the timezone,

 

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); formatter.setTimeZone(TimeZone.getTimeZone("GMT-4"));

 String timestamp = formatter.format(new Date());

 

 

in blackberry, i followed the same way,

 

 

Calendar calendar = Calendar.getInstance();

calendar.setTimeZone(TimeZone.getTimeZone("GMT-4"));

SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String timestamp1 = formatter1.format(calendar.getTime());

 

 

its not working in blackberry.

 

Please help me in setting the timezone in blackberry

 

VSK

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: ho to set timezone in blackberry

You code is not the same is it.  BlackBerry formatter does not support setting a TimeZone. 

 

I believe you can do something like what you want using DateFormat, but I've never done it.  Search the forum, I remember seeing some other Thread which discussed this. 

 

 

New Contributor
happyboyz
Posts: 6
Registered: ‎09-21-2011
My Device: Pearl 9100

Re: ho to set timezone in blackberry

from your Calendar use a manual format, without formatter, like this:

 

String time = calendar.get(Calendar.HOUR_OF_DAY) + ":" +calendar.get(Calendar.MINUTE) + ":" +calendar.get(Calendar.SECOND);

 

formatter will reset your timezone format to default x_x

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: ho to set timezone in blackberry

I have not tried it, but Calendar supports a timezone:
http://www.blackberry.com/developers/docs/7.1.0api/java/util/Calendar.html#setTimeZone(java.util.Tim...
and SimpleDateFormat supports Calendar:
http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/i18n/SimpleDateFormat.html#for...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter