DateFormat dateFormat = new SimpleDateFormat ("EEE, d MMM Y HH:mm:ss Z", Locale.ENGLISH);
String date = "Mon, 21 Oct 2013 22:21:00 +0400";
dateFormat.format(dateFormat.parse(date)); // returns "Mon, 31 Dec 2013 22:21:00 +0400"
为什么结果字符串与月份和月份中的输入日期变量不同?
最佳答案
之所以得到该输出,是因为使用了错误的格式。您应该使用y
(小写)作为年份,而不是Y
-用于week year
"EEE, d MMM y HH:mm:ss Z"
关于java - 什么时候dateformat解析和format方法不对称?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19502672/