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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With