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: 214
Registered: ‎03-18-2012
My Device: 8520
My Carrier: Company

problem while fetching network time..

Sir,below is the code that i use to fetch the  network time...and it gives me  wrong result...

 

 long lNetworkMilliseconds = RadioInfo.getNetworkTime(System.currentTimeMillis());

 String time=new SimpleDateFormat("H:m:s").format(new Date(lNetworkMilliseconds));

 

e.g if network tme is  15:52 it give me 3.21

    

 

 

 

Developer
Posts: 16,612
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: problem while fetching network time..

re-read the javadoc of SimpleDateFormat.
----------------------------------------------------------
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
Developer
Posts: 214
Registered: ‎03-18-2012
My Device: 8520
My Carrier: Company

Re: problem while fetching network time..

i have tested the same code 1 month before and it works fine...but now it is gives  wrong time....

please suggest where i am wrong....

Developer
Posts: 16,612
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: problem while fetching network time..

i suggest that you use the debugger to check if the returned value is correct.
then check if your formatting works correctly.
----------------------------------------------------------
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
Developer
Posts: 214
Registered: ‎03-18-2012
My Device: 8520
My Carrier: Company

Re: problem while fetching network time..

ok thanx,

                   now i get the time according to 12 hours.but i want to get according to 24 horus...please suggest

Developer
Posts: 16,612
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: problem while fetching network time..

the long value is a timestamp, it is not formatted, that means you get the correct time or not, but not "12 hours" or "24 hours".
please think about what you are doing, and if you have a problem receiving the time (as indicated in the topic) or a problem formatting a correct timestamp.

http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/i18n/SimpleDateFormat.html has a fairly good java doc.
you can determine how many digits should be used when creating the format.

for 24-h format you could, for example, use "HH:mm" or "HH:mm:ss"
----------------------------------------------------------
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