This behaviour is because the SimpleDateFomat
does not impose itself upon the date. The SimpleDateFormat
is merely a pattern to get a formated output out of any Date
, but it does not change the date itself. Date
does not have a format, so
System.out.println("before format "+invoiceDate);
defaults to the default pattern format.
Actually, the SimpleDateFormat
is exactly the way to achieve what you want, ie use it to properly format your output everytime you need it. Formating a date object gives you a representation of it, a String
.