Java shows wrong current year

I wrote code to print the current date.

Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("ddMMYYYY");
String newdate = dateFormat.format(date);

But it gives the result as: The 29122016
actual output should be: The 29122015
system date is also correct.

What is wrong with the code?

+4
source share
1 answer

Yindicates a weekly year. You must change to:

DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy");

SimpleDateFormat contains the following data:

Letter | Date or Time Component | Presentation | Examples
-------+------------------------+--------------+----------
y      | Year                   | Year         | 1996; 96
Y      | Week year              | Year         | 2009; 09
+11
source

Source: https://habr.com/ru/post/1622058/


All Articles