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
New Developer
Posts: 35
Registered: ‎04-16-2009
My Device: Not Specified

String to Date conversion

Hey folks...

 

Hopefully, I'm asking better questions now.  Don't  feel like a *total* newbite these days...

 

But this one if baffling me...

 

According to everything I've read, I should be able to use the HttpDateParser class in
net.rim.device.api.io.http.HttpDateParser to send a string and get back a date (long).

 

In the documentation for the class it says:

 

parse
public static long parse(String date)

 

However, when I try to compile this line:

 

HttpDateParser httpdateparser = new HttpDateParser();

 

I get this error message:

HttpDateParser() has private access in net.rim.device.api.io.http.HttpDateParser

 

WTF?  Am I wrong or is there a difference between the 'public' assignation in the doc and the 'private' in the error message?

 

Thanks in advance!

 

-- John Kiernan

 

 

Developer
Posts: 507
Registered: ‎07-15-2008
My Device: Not Specified

Re: String to Date conversion

[ Edited ]

This class does not have public constructor.

 

And parse(String) method is static.

 

Call this method as follows

 

 

long parsedDate = HttpDateParser.parse(string2Parse);

Message Edited by rafo on 15-05-2009 12:28 AM
----------------
if your issue solved set "Solution" mark at the relevant post
Developer
Posts: 507
Registered: ‎07-15-2008
My Device: Not Specified

Re: String to Date conversion

static class methods and class fields do not require to build class instance to invoke/access them.

 

Moreover even it is possible it is encouraged to access static methods/fields via class reference rather than class instance reference.

 

 

----------------
if your issue solved set "Solution" mark at the relevant post
Highlighted
New Developer
Posts: 35
Registered: ‎04-16-2009
My Device: Not Specified

Re: String to Date conversion

Thanks for everyone's help.  As it turned out, I didn't really have all of the data necessary to dso this conversion (I could have fudged it, I suppose), but here's what I ended up doing (it involved a Calendar object):

 

    public static DateFormat myDF = new SimpleDateFormat("MM/dd/yy");


            String workstring = singlerecord._Workdate;
            String monthstr = workstring.substring(0,2);
            String daystr = workstring.substring(3,5);
            String yearstr = workstring.substring(8,10);
            int monthnum = Integer.parseInt(monthstr);
            int daynum = Integer.parseInt(daystr);
            int yearnum = Integer.parseInt(yearstr);
           
            Calendar getCal = Calendar.getInstance();
            getCal.set (Calendar.MONTH,monthnum );
            getCal.set(Calendar.DAY_OF_MONTH,daynum);
            getCal.set(Calendar.YEAR,yearnum);
            Date thedate = getCal.getTime();
            long workdate = thedate.getTime();
           
            MyDateField     wdfield = new MyDateField("", workdate, myDF, DrawStyle.LEFT, 1, rowcount);
 

Thanks for everyone's help!

 

-- John