如何以 "yyyy/MM/dd HH:mm:ss" 格式格式化给定日期“31.12.9999”
How to format the given date "31.12.9999" in the format "yyyy/MM/dd HH:mm:ss"
有个共同的疑问很久了。在日期形成过程中,如果输入日期的格式类似于“2019/05/22 02:00:23”,那么在下一行的帮助下我们可以格式化日期,
String inputDate = "2019/05/22 02:00:23";
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date toDate = dateFormatter.parse(inputDate);
我可以看到输入格式和要求的格式是一样的。假设如果我像下面这样更改输入日期,它会显示 java.text.ParseException: Unparseable date: exception.
String inputDate = "31.12.9999";
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
Date toDate = dateFormatter.parse(inputDate);
请建议如何实现。
请尝试下面我提到的日期格式代码,希望对您有所帮助,
由此,
String inputDate = "31.12.9999";
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
Date toDate = dateFormatter.parse(inputDate);
要更改:
Date date = new SimpleDateFormat("dd.MM.yyyy").parse("31.12.9999");
String formattedDate = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(date);
System.out.println("formattedDate :: " + formattedDate);
谢谢,。
有个共同的疑问很久了。在日期形成过程中,如果输入日期的格式类似于“2019/05/22 02:00:23”,那么在下一行的帮助下我们可以格式化日期,
String inputDate = "2019/05/22 02:00:23";
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date toDate = dateFormatter.parse(inputDate);
我可以看到输入格式和要求的格式是一样的。假设如果我像下面这样更改输入日期,它会显示 java.text.ParseException: Unparseable date: exception.
String inputDate = "31.12.9999";
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
Date toDate = dateFormatter.parse(inputDate);
请建议如何实现。
请尝试下面我提到的日期格式代码,希望对您有所帮助,
由此,
String inputDate = "31.12.9999";
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
Date toDate = dateFormatter.parse(inputDate);
要更改:
Date date = new SimpleDateFormat("dd.MM.yyyy").parse("31.12.9999");
String formattedDate = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(date);
System.out.println("formattedDate :: " + formattedDate);
谢谢,。