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

string to date conversion

i have string with date like String dateToParse = "01/04/2004"; and i need to convert it into 01 Jan 2004
i have used the folllowing code but giving me wrong output= 01/Jan/1970

can any body correct my code..?

String dateToParse = "01/04/2004";
Date formatter = new Date(HttpDateParser.parse(dateToParse));
SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy");
int offset = TimeZone.getDefault().getRawOffset();
formatter.setTime(formatter.getTime() + offset);
String strCustomDateTime = dateFormat.format(formatter);
System.out.println("date output="+strCustomDateTime);
add(new LabelField(""+strCustomDateTime));

 

Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: string to date conversion

as stated in your other thread about it, httpdateparser is very peculiar about its input.
use substring and a Calendar object instead, you can most likely copy the code from somewhere as it is a quite common task.
----------------------------------------------------------
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