我在将日期转换为不同格式的字符串时遇到问题。日期:
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有关将日期从一种格式转换为另一种格式的更多详细信息。
关于java - 使用 simpledateformat 将日期转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15111127/