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
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009

Re: How to get time of current TimeZone ?

Ok Thanks a lot for the clarifications...

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

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)?

Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009

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.

 

 

 

 

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

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());

Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009

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"

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

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();

 

Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009

Re: How to get time of current TimeZone ?

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

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

Re: How to get time of current TimeZone ?

Can we mark this as Solved then?

Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009

Re: How to get time of current TimeZone ?

I have marked it as solved.

 

Thansk a lot for the help...

Please use plain text.
Contributor
rincethomas33
Posts: 29
Registered: ‎12-31-2010

Re: How to get time of current TimeZone ?

what is 

gmtOffset_Milisec 
Please use plain text.