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
Contributor
Posts: 35
Registered: ‎03-04-2010
My Device: 9381
My Carrier: Vodafone

Date formatting

I want to format the date in the following format dd-mm-yy.

 

How can i format it in blackberry jde

Developer
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Date formatting

[ Edited ]

Using Calendar class you can able to get date, month and year informations by calling get(). then you concatenate them to your own format.

 

code snippet:

     Calendar cal = Calendar.getInstance();

      int date = cal.get (Calendar.DATE);

     int month = cal.get (Calendar.MONTH) + 1;

     int year = cal.get (Calendar.YEAR);

 

     String dateFormat = date + "-" + month + "-" + (year % 100);

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Developer
Posts: 16,687
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Date formatting

too complicated.

 

you can use DateFormat for standard formatting, and SimpleDateFormat for adjustable formatting. Well documented in the java docs.

----------------------------------------------------------
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
Contributor
Posts: 11
Registered: ‎03-04-2010
My Device: 9000
My Carrier: vodafone

Re: Date formatting

[ Edited ]

You can try this

 

SimpleDateFormat sdf =

 new SimpleDateFormat("dd-MM-yyyy");

 

sdf.format(calendar);

 

calendar would be your calendar object . The format function returns String .

Regards,

Alpa

Developer
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Date formatting

Thank you guys, for giving me simpler format for date formatting

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------