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
GPSemailing
Posts: 23
Registered: ‎07-28-2008
My Device: Not Specified
Accepted Solution

HOW TO Timestamp() -> simpledateformat() ?

Hi Community

 

I have been looking for best practise to convert "tim" (Java statement below) in milli-seconds (since 1970 midnight) to human readable Date & Time.

 

I know roughly about SimpleDateFormat() but not sure how to implement it.

 

If anyone knows or can provide a sample code that will be great.

 

****

String tim = Long.toString(l.getTimestamp()); // timestamp

****

 

Thanks in advance

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

Re: HOW TO Timestamp() -> simpledateformat() ?

SimpleDateFormat needs an Object for input, in this case it would be a Date.
l.getTimestamp() seems to deliver a long, you can create a new Date from it.

here is an example of an formatted full date with 24h notation:

SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm");
String tim = sdf.format(new Date(l.getTimestamp()));
----------------------------------------------------------
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
New Developer
GPSemailing
Posts: 23
Registered: ‎07-28-2008
My Device: Not Specified

Re: HOW TO Timestamp() -> simpledateformat() ?

Many Thanks for your reply.

 

I tried to use the above lines of code as it is and got few errors.

 

java:49: cannot find symbol

symbol : class SimpleDateFormat

 

location : class ................

.....................................

 

I also used

 

import net.rim.device.api.i18n.Format.*;

 

But I am still getting error. Pardon me for my inexpertese with Java.

 

Thanks again

Developer
richard_puckett
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: HOW TO Timestamp() -> simpledateformat() ?

[ Edited ]

Let me ask seriously: Do you program w/o using the Javadocs?  I can't even tie my shoes without looking at the Javadocs first - they're indispensable.  If you open the Javadocs and browse through the alphabetical list of classes you'll find SimpleDateFormat in net.rim.device.api.i18n (Format isn't a package, it's a class so you shouldn't be trying to do a wildcard import with it).

 

import net.rim.device.api.i18n.SimpleDateFormat;

 

Even better, if you use Eclipse you can put your cursor on the SimpleDateFormat word and hit ctrl-shift-m and it will add the import for you.  In NetBeans do ctrl-shift-i.

Message Edited by richard_puckett on 08-13-2008 09:27 AM
New Developer
GPSemailing
Posts: 23
Registered: ‎07-28-2008
My Device: Not Specified

Re: HOW TO Timestamp() -> simpledateformat() ?

Sorry Richard, for not doing my homework. I did have a look at the java docs and with my limited knowledge in Java I did have

 

import net.rim.device.api.i18n.SimpleDateFormat.*;         //in my code

 

But after looking at your reply I removed (.*) at the end of my import. Since all the imports in my code had .* at the end I assumed that as a syntax which wasnt true.

 

My Sincere Thanks!

Regards

Adi 

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

Re: HOW TO Timestamp() -> simpledateformat() ?

if you use Eclipse you can put your cursor on the SimpleDateFormat word and hit ctrl-shift-m and it will add the import for you.


and ctrl+shift+o organizes all imports (adding all required, removing all not required).
----------------------------------------------------------
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
New Developer
GPSemailing
Posts: 23
Registered: ‎07-28-2008
My Device: Not Specified

Re: HOW TO Timestamp() -> simpledateformat() ?

Thanks Simon

 

I am using JDE and probably would like to use eclipse down the track, as you descibed there are benifits in doing that.

 

 

 

 

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

Re: HOW TO Timestamp() -> simpledateformat() ?

i use eclipse as my editor and compile using the JDE, except for bigger projects where i use the full integration into eclipse via ant.

to start all you have to do is remove the Java SDK from the build path, add the rim api jar instead and switch the java compiler to 1.4.

i would never ever code again in the JDE!
----------------------------------------------------------
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