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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
New Developer
vsk
Posts: 15
Registered: ‎12-03-2009

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

 

Please use plain text.
Developer
peter_strange
Posts: 17,959
Registered: ‎07-14-2008

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. 

 

 

Please use plain text.
New Contributor
happyboyz
Posts: 6
Registered: ‎09-21-2011

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

Please use plain text.
Developer
simon_hain
Posts: 14,064
Registered: ‎07-29-2008
My Carrier: O2 Germany

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
Please use plain text.