小编Jee*_*eet的帖子

如何将时间戳字符串更改为“DD.MM.YYYY”?

我需要不同格式的字符串来转换为“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)

但是,我没有得到正确的输出。我怎样才能得到我想要的结果?

java string datetime date

2
推荐指数
2
解决办法
948
查看次数

标签 统计

date ×1

datetime ×1

java ×1

string ×1