将日期转换成不同的格式
convert date into different format
我正在尝试将日期转换为用户需要的格式。我想要所有格式的日期。
但是日期格式不对请帮忙
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
谢谢。
D Day in year Number 189
d Day in month Number 10
来自 https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
因此,格式应如下所示:
String dateFormats[] =
{
"yyyy/MM/dd",
"dd/MM/yyyy",
"dd-MM-yyyy",
};
由于 java 代码语法区分大小写,所以出错了。
请在 https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html 检查正确的日期和时间模式
您的模式字符串数组应转换为:
String dateFormats[] =
{
"yyyy/MM/dd",
"dd/MM/yyyy",
"dd-MM-yyyy",
};
我正在尝试将日期转换为用户需要的格式。我想要所有格式的日期。 但是日期格式不对请帮忙
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
谢谢。
D Day in year Number 189
d Day in month Number 10
来自 https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
因此,格式应如下所示:
String dateFormats[] =
{
"yyyy/MM/dd",
"dd/MM/yyyy",
"dd-MM-yyyy",
};
由于 java 代码语法区分大小写,所以出错了。 请在 https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html 检查正确的日期和时间模式
您的模式字符串数组应转换为:
String dateFormats[] =
{
"yyyy/MM/dd",
"dd/MM/yyyy",
"dd-MM-yyyy",
};