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
Developer
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to get time of current TimeZone ?

Ok Thanks a lot for the clarifications...

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

Re: How to get time of current TimeZone ?

Is this solved then? 

 

Would it be possible to post the code that you are using to output the Time Zone Offset (Z)?

Developer
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to get time of current TimeZone ?

[ Edited ]

OK.

 

 

TimeZone _timeZone = TimeZone.getDefault();                // Asia/Calcutta
boolean isDayLightSavings = _timeZone.useDaylightTime();
Calendar _calendar = Calendar.getInstance();
int gmtOffset = _timeZone.getOffset(1, _calendar.get(Calendar.YEAR), _calendar.get(Calendar.MONTH), _calendar.get(Calendar.DATE), _calendar.get(Calendar.DAY_OF_WEEK), _calendar.get(Calendar.MILLISECOND));

int gmtOffset_Hr = gmtOffset_Milisec/DateTimeUtilities.ONEHOUR;
int gmtOffset_Min = (gmtOffset_Milisec % DateTimeUtilities.ONEHOUR)/DateTimeUtilities.ONEMINUTE;

 

Then I gets gmtOffset_Hr =  5 & gmtOffset_Min = 30. Then after using Strign methods on it I gets it as +05 & 30 and put it in

 

 

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss "+gmtOffset_HH.trim()+gmtOffset_MM.trim());
Date date = new Date();
date.setTime(System.currentTimeMillis());
String formattedDate = dateFormat.format(date).toString();

 

Thanks for the suggestions... got it ? let me know if any problem.

 

 

 

 

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

Re: How to get time of current TimeZone ?

Happy with the first block of you code.  Be aware that

 

boolean isDayLightSavings = _timeZone.useDaylightTime();


only tells you if the Time Zone uses Daylight Saving, not whether it is currently in a Daylight Saving period.

 

Not sure that your second block actually compiles?  This doesn't look right:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss "+gmtOffset_HH.trim()+gmtOffset_MM.trim());

Developer
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to get time of current TimeZone ?

but

 

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss "+gmtOffset_HH.trim()+gmtOffset_MM.trim());

 

gives me correct time as "currenttime +0530"

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

Re: How to get time of current TimeZone ?

[ Edited ]

Ahh I see. 

 

You realize that you are passing in the String as a parameter to your SimpleDateFormat, which it then thinks is a constant and so does not do substitution. 

 

It would normally have been written as follows, which I am happy with:

 

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
Date date = new Date();
date.setTime(System.currentTimeMillis());
String formattedDate = dateFormat.format(date).toString() +gmtOffset_HH.trim()+gmtOffset_MM.trim();

 

Developer
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to get time of current TimeZone ?

Hey thanks. Its working with ur code.. Thanks a lot....

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

Re: How to get time of current TimeZone ?

Can we mark this as Solved then?

Developer
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to get time of current TimeZone ?

I have marked it as solved.

 

Thansk a lot for the help...

Highlighted
Developer
Posts: 72
Registered: ‎12-31-2010
My Device: 9800
My Carrier: Airtel

Re: How to get time of current TimeZone ?

what is 

gmtOffset_Milisec 
R33