【发布时间】:2016-04-07 12:21:08
【问题描述】:
我正在尝试将日期转换为用户所需的格式。我想要所有格式的日期。 但是格式的日期是错误的,请帮忙。
package DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormat
{
DateFormat() throws ParseException
{
String dateFormats[] =
{
"YYYY/MM/DD",
"DD/MM/YYYY",
"DD-MM-YYYY",
};
for (int i = 0; i < dateFormats.length; i++)
{
String newDate = new SimpleDateFormat(dateFormats[i]).format(new Date());
System.out.println(newDate);
}
}
public static void main(String[] args) throws ParseException
{
new DateFormat();
}
}
输出是
2016/04/98
98/04/2016
98-04-2016
谢谢。
【问题讨论】:
-
因为,使用了错误的格式。请参阅documentation 了解支持的格式。
标签: java date date-format date-formatting