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
pg1181
Posts: 398
Registered: ‎01-12-2011
My Device: Q10

Re: Date/String Conversions

[ Edited ]

I tried the following:

 

Calendar now = Calendar.getInstance();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd h:mm:ss");new StringBuffer(), null).toString();

String formattedDate = formatter.format(now,

Date myDate = new Date(HttpDateParser.parse(formattedDate));

myUser.LastUpdateDate = myDate;

result = myUser.LastUpdateDate.toString();

 

This is the output when I print result:

Wed Dec 31 19:00:00 America/New_York 1969

Which is obviously not in the desired format. What am I doing wrong?

Please use plain text.
Developer
jprofitt
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Date/String Conversions

Try setting result=formattedDate; and see if that gets you what you're needing

Please use plain text.
Super Contributor
pg1181
Posts: 398
Registered: ‎01-12-2011
My Device: Q10

Re: Date/String Conversions

Good morning. And yes it does print out in the desired format. But this brings me back to square one. I have to initialize a Date object with this string. If I say Date myDate = new Date(HttpDateParser(formattedDate)); and try to print that out, it puts it back in the weird format. How can I be completely sure that my date object is in the right format?

Please use plain text.
Developer
jprofitt
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Date/String Conversions

Well the Date object is just a container for a "long" that is holding the time. The methods that are applied to it simply reflect it changing that long. The format you are seeing is just what it shows when you call .toString() but isn't necessarily how it sees itself or how something else will see it.

 

What ultimately is your server wanting to see when you send it this object?

Please use plain text.
Super Contributor
pg1181
Posts: 398
Registered: ‎01-12-2011
My Device: Q10

Re: Date/String Conversions

it's a .Net DateTime object that it's expecting. This is usually in the format that I mentioned, yyyy/mm/dd hh:mm:ss, I'm not getting a response back from the service so I'm guessing it has something to do with the date I've been sending. But I could be completely wrong. For all I know the date could be fine, it might be something else messing up the response.

Please use plain text.
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Date/String Conversions

You have to use the formatter. A Date object's toString function has the format of "EEE MMM dd hh:mm:ss zzz yyyy" while you are using a format of "yyyy-mm-dd h:mm:ss". If you need to store a Date object, go ahead. if you need to print out that Date object then use a formatter.

---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.
Please use plain text.