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
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

regarding date format

i have date coloum in database, and i' have retrieve that date from my database. the format of my date in my database is 31/01/2013, now i want to convert that format into 31 Janurary 2013.can u help me..?

Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: regarding date format

sqlite should give you a date object, you can use SimpleDateFormat to get a formatted output in any format you want.
----------------------------------------------------------
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
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: regarding date format

"sqlite should give you a date object,"

Does this depend on how you have defined the column?

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: regarding date format

yes i got the date from my Sql database by using

System.out.println("DATEEEEE=="+row.getObject(3)); //like 04/04/2013
String date = ""+row.getObject(3);

and i have put it into a string date.

now i want to convert ot into 04 April 2013 

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: regarding date format

The only two methods I am aware of to convert a String to a Date are:

a) Use HttpDateParser, if your String matches the formats it supports

b) Hand craft a conversion yourself, which is pretty easy if long winded using a Calendar Object and extracting the components (month, day, year) from the String, and set ing these in the Calendar Object.  Don't forget for a Calendar Object, Month 0 is January. 

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: regarding date format

[ Edited ]

yes i have use HttpDateParser but that was giving me wrong output

 

String date = ""+mr.getObject(3).toString();
/*Date eventDate = new Date(HttpDateParser.parse(date));
SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy");
String eventDateString = dateFormat.format(eventDate);
System.out.println("raw date=" + date + ", parsed string=" + eventDateString);

 

here  i have date 04/02/2013(from my database)

and my converted is showing 01 January 1970

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: regarding date format

[ Edited ]

I've not checked, but I suspect that means your format is not supported - review the API. 

I guess you will have to use method (b) from my previous post.

Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: regarding date format

ok, i thought sqlite would give you a date object, seems that is not the case.
you would have to parse the date yourself, then, as the format is defined that should not be an issue using substring and a calendar object.
retrieve the date from the calendar and use simpledateformat then.
----------------------------------------------------------
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
Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: regarding date format

yes, i think so, but i did not know how to get the (day,month,year) from String date = "04/02/2013";

can u help me..

Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: regarding date format

use http://www.blackberry.com/developers/docs/7.1.0api/java/lang/String.html#substring(int,%20int)
counting the char index should be something a developer should be able to do, otherwise just experiment until the correct values come out :smileywink:
----------------------------------------------------------
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
Please use plain text.