我已经编写了打印当前日期的代码。
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("ddMMYYYY");
String newdate = dateFormat.format(date);
但它给出的输出为:29122016
实际输出应该是:29122015
系统日期也是正确的。
代码有什么问题?
最佳答案
Y
表示一周年。您应该更改为:
DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy");
SimpleDateFormat
有详细信息:
Letter | Date or Time Component | Presentation | Examples
-------+------------------------+--------------+----------
y | Year | Year | 1996; 96
Y | Week year | Year | 2009; 09
关于Java 显示不正确的当前年份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34507820/