02-07-2011 09:23 AM - edited 02-07-2011 09:24 AM
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?
02-07-2011 10:25 AM
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?
02-07-2011 10:38 AM
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?
02-07-2011 10:46 AM
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.
02-07-2011 10:47 AM
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.