我在将日期转换为不同格式的字符串时遇到问题。日期:
lastDownloadDate>>Wed Feb 27 16:20:23 IST 2013
lastChangeDate>>Wed Feb 27 15:11:00 IST 2013
我想将此格式转换为另一种格式:yyyy-mm-dd HH:mm:ss
.
当我尝试转换它时,我使用以下方法得到不同的结果:
DateFormat outputFormat = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
String lastDownloadTimeVal = outputFormat.format(lastDownloadDate);
System.out.println("lastDownloadTimeVal>>"+lastDownloadTimeVal);
String lastChangeTimeVal = outputFormat.format(lastChangeDate);
System.out.println("lastChangeTimeVal>>"+lastChangeTimeVal);
我得到了错误的结果,月份被替换为分钟:
lastDownloadTimeVal>>2013-20-27 16:20:23
lastChangeTimeVal>>2013-11-27 15:11:00
yyyy-mm-dd HH:mm:ss
这是错误的。这应该是yyyy-MM-dd HH:mm:ss
。
参考这个http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html有关将日期从一种格式转换为另一种格式的更多详细信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)