This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
They are the same thing, aren't they? Bear in mind that a Date is not a String. A Date is just a number of milliseconds from a certain instant of time, that's all.
What you are looking at when you see "Sun May 04 00:00:00 EST 2008" is simply a string representation of the Date. It isn't the Date itself, which is just that number of milliseconds. And if you want a different string representation, then you use that same SimpleDateFormat object to format it as a String.
Originally posted by sam barker: But when you phase a string with the format "yyyy-MM-dd" shouldnt yu get the date in "yyyy-MM-dd" format ?.
No. You didn't understand what I originally said. Dates aren't ever "in a format". Date doesn't have a concept of "format" in any way. The idea of a Date being "in a format" doesn't mean anything.
If you just do System.out.println(someDate), that prints a String representation of the Date object using the standard format for Date objects. That's probably what you're seeing. The Date object doesn't remember how it was created, it's just a Date, that's all. If you want to display a differently-formatted String representation of the Date, well, we went through that already.