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: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido
Accepted Solution

SimpleDataFormat.parse

Hi. All the tutorials I have seen about dates in java mention a method SimpleDateFormat.parse(string str). This takes a string as an arguments and returns a date. The thing is the following message keeps popping up in my Eclipse IDE.

 

"The method parse(String) is undefined for the type DateFormat"

 

Now I know what this means. Obviously my version of java doesn't support this method. How can I make this method available? Do I have to upgrade something specific? And can this be done from within Eclipse as I don't want to start reinstalling things. Thanks a lot.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: SimpleDataFormat.parse

You are not missing anything.  You can't upgrade to get this.  The only date parser that I think is on device is HttpDateParser. 

Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: SimpleDataFormat.parse

I think you might be right. Now I just need to know how to get my date in the format:

 

2011-02-04 19:28:00 +0000

 

Or at least something close as opposed to what I'm getting now:

 

Mon Feb 26 15:15:00 America/New_York 2007

 

Thanks.

Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: SimpleDataFormat.parse

[ Edited ]

After having searched through the forums and other sites, I've come to the conclusion that SimpleDateFormat.parse is definitely being used by Blackberry Developers. Where is this method and how do I get it? I'm apologize if I sound impatient, but it should be simple to convert dates to string and vice-versa. I'm a .Net kind of programmer and am not familiar with the different versions of Java.

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: SimpleDataFormat.parse

I somewhat doubt that SimpleDateFormat.parse is being used because it doesn't exist.

 

As for Java:

Non-mobile devices use J2SE which has many of the functions newcomers here often can't find.

BlackBerry uses J2ME which is a subset of J2SE, so not everything is included. It's best to have the BlackBerry documentation up so you can see what is and is not avalible for you to use.

 

On the note of the documentation, if you open it and look for HttpDateParser like you have been recommended then you can parse the date as you are trying to do. You can then take the returned value and pass it into a Date object, which can be passed into a Calendar object, which can be converted into a different format as jprofitt and I have mentioned in your other post about how to format dates.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: SimpleDataFormat.parse

I've looked at HttpDateParser. It has one method called parse(string str), which returns a long. And this long can be used to initialize a Date object, and seems to be the only way to initialize a Date object. So your saying I can pass the Date into a Calendar object?

 

So I'm doing:

 

Date myDate = new Date(HttpDateParser.parse("2011-04-11"));

 

And the long in this case is basically how many milliseconds have passed since some date back in 1970. Got it. Now I cannot instantiate a Calendar object, so I guess I'm calling static methods right? I should say Calendar.something(arguments), I'm looking at the docs for Calendar right now, not sure where to start. Remember, when all the smoke clears I want a Date object, in the proper format, so that I can send it along with a web service call. And if I say Date.ToString() I would like it to take on my format. Do you have any examples handy?

Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: SimpleDataFormat.parse

Sorry, spent so much time type up my last reply that I didn't notice the code snippet you posted.

Highlighted
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: SimpleDataFormat.parse

Thanks rcmaniac, you're explanation of J2SE and J2ME really cleared up some confusion.