Java 将日期转换为不同格式
我正在尝试将日期转换为用户所需的格式。我想要所有格式的日期。 但格式化日期错误,请帮助Java 将日期转换为不同格式,java,date,date-format,date-formatting,Java,Date,Date Format,Date Formatting,我正在尝试将日期转换为用户所需的格式。我想要所有格式的日期。 但格式化日期错误,请帮助 package DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateFormat { DateFormat() throws ParseException { String dateFormats
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();
}
}
多谢各位
D Day in year Number 189
d Day in month Number 10
从
因此,格式应该如下所示:
String dateFormats[] =
{
"yyyy/MM/dd",
"dd/MM/yyyy",
"dd-MM-yyyy",
};
从
因此,格式应该如下所示:
String dateFormats[] =
{
"yyyy/MM/dd",
"dd/MM/yyyy",
"dd-MM-yyyy",
};
这是因为java代码语法区分大小写。 请检查正确的日期和时间模式 模式的字符串数组应转换为:
String dateFormats[] =
{
"yyyy/MM/dd",
"dd/MM/yyyy",
"dd-MM-yyyy",
};
这是因为java代码语法区分大小写。 请检查正确的日期和时间模式 模式的字符串数组应转换为:
String dateFormats[] =
{
"yyyy/MM/dd",
"dd/MM/yyyy",
"dd-MM-yyyy",
};
因为,使用了错误的格式。有关支持的格式,请参阅。因为,使用了错误的格式。有关支持的格式,请参阅。
YYYY
也应为小写,yyy
。yyy
也应为小写,yyy
。