02-04-2011 01:06 PM
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.
Solved! Go to Solution.
02-04-2011 02:32 PM
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
02-04-2011 03:38 PM - edited 02-04-2011 03:42 PM
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.
02-04-2011 04:07 PM
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.
02-04-2011 04:30 PM
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?