【发布时间】:2012-11-03 07:52:07
【问题描述】:
我在 Java 中有一个字符串,它是一个日期,但格式如下:
02122012
我需要重新格式化它,使其看起来像 2012 年 2 月 12 日 怎么做。
使用以下代码,我不断返回 java.text.SimpleDateFormat@d936eac0
下面是我的代码..
public static void main(String[] args) {
// Make a String that has a date in it, with MEDIUM date format
// and SHORT time format.
String dateString = "02152012";
SimpleDateFormat input = new SimpleDateFormat("ddMMyyyy");
SimpleDateFormat output = new SimpleDateFormat("dd/MM/yyyy");
try {
output.format(input.parse(dateString));
} catch (Exception e) {
}
System.out.println(output.toString());
}
【问题讨论】:
-
同意亚历克斯,即使这意味着 02122012,你有什么尝试?
-
@BlueBullet:您已经编辑了原始问题假设,这只是一个错字。我宁愿从 OP 那里听到。
-
我不断返回 java.text.SimpleDateFormat@d936eac0