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
Regular Contributor
Posts: 94
Registered: ‎02-27-2010
My Device: rien
My Carrier: etudiant

full date

 

hi

 

 

How can I convert a string (eg 2010-7-10) to a full day (Monday 10 July 2010) with predefined functions??

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: full date

You could parse the values and pass them to a Date/Calendar object then use the SimpleDateFormat class to print the values back in that form.

New Contributor
Posts: 9
Registered: ‎03-18-2010
My Device: Bold 9000
My Carrier: Rogers

Re: full date

Try 

 

long date = net.rim.device.api.io.http.HttpDateParser.parse("2010-7-10");

 

it should work. You can then use 

 

net.rim.device.api.i18n.DateFormat

 

to get it in desired format (also localized, if you want).

 

 

--
Regular Contributor
Posts: 94
Registered: ‎02-27-2010
My Device: rien
My Carrier: etudiant

Re: full date

I tried but does not work, you can help me and give me an example code thank you
New Contributor
Posts: 9
Registered: ‎03-18-2010
My Device: Bold 9000
My Carrier: Rogers

Re: full date

 

This works, I checked:

 

 

public static void main(String[] args)
{
	long date = net.rim.device.api.io.http.HttpDateParser.parse("2010-07-10");
	DateFormat d = DateFormat.getInstance(DateFormat.DATE_LONG);
	System.out.println(d.format(new Date(date)));	
}

 

 

it prints: Sat, 10 Jul 2010

 

Your problem is, the month (and probably day) is single digit, not double digit (e.g. 2010-7-1)

If is up to you what to do with it... Either write completely your own parser, or make them two digits using indexof and charat function. 

--
Highlighted
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: full date

If you use the SimpleDateFormat class and a Calendar/Date object, you can format the date any way you want. Look at the class in the JDE docs, it's very flexible and easy to use.