1

I'm having issues when converting a date to string in a different format. The date:

lastDownloadDate>>Wed Feb 27 16:20:23 IST 2013
lastChangeDate>>Wed Feb 27 15:11:00 IST 2013

I want to convert this format to another format: yyyy-mm-dd HH:mm:ss.

When I try to convert it I'm getting different results using:

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);

I'm getting the wrong result, the month is being replaced with minutes:

lastDownloadTimeVal>>2013-20-27 16:20:23
lastChangeTimeVal>>2013-11-27 15:11:00
4

5 回答 5

1

您使用了错误的月份格式。

yyyy-mm-dd HH:mm:ss ----> yyyy-MM-dd HH:mm:ss
mm--->Minutes. 
MM--->Months
于 2013-02-27T11:38:57.867 回答
1

yyyy-mm-dd HH:mm:ss这是错误的。这应该是yyyy-MM-dd HH:mm:ss。有关将日期从一种格式转换为另一种格式的更多详细信息,请参阅此http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

于 2013-02-27T11:38:43.713 回答
0

尝试

DateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
于 2013-02-27T11:38:57.347 回答
0

改变

DateFormat outputFormat = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");

DateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
于 2013-02-27T11:39:19.393 回答
0
DateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
mm for Minutes
MM for Months
于 2013-02-27T11:49:16.980 回答