我需要不同格式的字符串来转换为“DD.MM.YYYY”。
"Thu, 3 Nov 2022 06:00:00 +0100"必须改为"03.11.2022"
和
"01.11.2022 20:00:00"到"01.11.2022"。
所有格式均为String.
我尝试做
String pattern="DD.MM.YYYY";
DateTimeFormatter formatter=DateTimeFormatter.ofPattern(pattern);
new SimpleDateFormat(pattern).parse("01.11.2022 20:00:00")
Run Code Online (Sandbox Code Playgroud)
我也尝试过执行以下操作
java.time.LocalDateTime.parse(
item.getStartdatum(),
DateTimeFormatter.ofPattern( "DDMMYYYY" )
).format(
DateTimeFormatter.ofPattern("DD.MM.YYYY")
)
Run Code Online (Sandbox Code Playgroud)
但出现错误:
Exception in thread "main" java.time.format.DateTimeParseException:
Text 'Sun, 30 Oct 2022 00:30:00 +0200' could not be parsed at index 0
Run Code Online (Sandbox Code Playgroud)
我也尝试执行以下操作
Exception in thread "main" java.time.format.DateTimeParseException:
Text 'Sun, 30 Oct 2022 00:30:00 +0200' could not be parsed at index 0
Run Code Online (Sandbox Code Playgroud)
但是,我没有得到正确的输出。我怎样才能得到我想要的结果?