Reputation: 1668
I have written code for printing current date.
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("ddMMYYYY");
String newdate = dateFormat.format(date);
But it gives output as : 29122016
Actual output should be : 29122015
The system date is also correct.
What is wrong with the code?
Upvotes: 4
Views: 192
Reputation: 95958
Y
denotes a week year. You should change to:
DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy");
The SimpleDateFormat
has the details:
Letter | Date or Time Component | Presentation | Examples
-------+------------------------+--------------+----------
y | Year | Year | 1996; 96
Y | Week year | Year | 2009; 09
Upvotes: 11