I’m trying to pass a Date-Object to a SOAP-API and need the output of the date-object itself to be yyyy-MM-dd
I’m already converting my string into a date-object like this:
// String __startDatum = "2013-02-05";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date convertedDate = dateFormat.parse(__startDatum);
For now the output of convertedDate will be Tue Feb 05 00:00:00 MEZ 2013.
How could I change the output of convertedDate to be 2013-02-05?
Please keep in mind I still need it to be a date-object not a string!
There’s no “output of
convertedDate” – it’s just aDatevariable. The only way to get “Tue Feb 05 00:00:00 MEZ 2013” would be to calltoString()on it, either implicitly or explicitly – and you can’t change the format used byDate.toString().It’s important to understand that a
Dateis just a number of milliseconds since the Unix epoch. It doesn’t have a time zone; it doesn’t have a calendar system; it doesn’t have a particular format.If you want a better API which allows you to create an object which just represents a date (rather than a date/time) you should look at Joda Time which is a far nicer date and time API than the built-in one. It’s reasonably large – primarily due to the time zone data, I believe – so you may want to look for a cut down version tailored to Android. It’s mostly a pleasure to work with though – at least compared with
DateandCalendar.