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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Regular Contributor
ramroum1986
Posts: 94
Registered: ‎02-27-2010
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??

Please use plain text.
Developer
Developer
CMY
Posts: 1,115
Registered: ‎02-10-2009
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.

Please use plain text.
New Contributor
APakka
Posts: 9
Registered: ‎03-18-2010
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).

 

 

--
Please use plain text.
Regular Contributor
ramroum1986
Posts: 94
Registered: ‎02-27-2010
My Carrier: etudiant

Re: full date

I tried but does not work, you can help me and give me an example code thank you
Please use plain text.
New Contributor
APakka
Posts: 9
Registered: ‎03-18-2010
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. 

--
Please use plain text.
Developer
Developer
CMY
Posts: 1,115
Registered: ‎02-10-2009
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.

Please use plain text.