0

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!

Thomas Schwärzl
  • 9,518
  • 6
  • 43
  • 69
  • Might help to find out what you actually need, if you would tell what you are calling in the soap-API. – Gjordis Feb 05 '13 at 08:30

1 Answers1

2

For now the output of convertedDate will be Tue Feb 05 00:00:00 MEZ 2013.

There's no "output of convertedDate" - it's just a Date variable. The only way to get "Tue Feb 05 00:00:00 MEZ 2013" would be to call toString() on it, either implicitly or explicitly - and you can't change the format used by Date.toString().

It's important to understand that a Date is 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 Date and Calendar.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194