【发布时间】:2014-05-20 14:18:07
【问题描述】:
我编写了这段代码,用于将我从网页中提取的字符串转换为日期格式。但是每当我运行它时,它都会将月份转换为 01。
你能帮我调试一下这段代码吗?
if (this.subject != null && !this.subject.isEmpty()) {
DateFormat userDateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date df = DATE_FORMAT.parse(this.subject);
Calendar cal = Calendar.getInstance();
cal.setTime(df);
String theDate = String.format("%tY-%tm-%td", cal, cal, cal);
return theDate;
}
【问题讨论】:
-
Can you please help me debug this code?为什么要我们调试这段代码? -
你为什么用
String.format(..)而不是SimpleDateFormat?