gpt4 book ai didi

java - "May 28, 2013 6:04:38 PM"是什么格式?

转载 作者:行者123 更新时间:2023-12-02 00:58:04 25 4
gpt4 key购买 nike

我尝试使用 SimpleDateFormat 将字符串“May 28, 2013 6:04:38 PM”解析为 Date,但我做不到。以下是我所做的:

public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss a");
try {
System.out.println(sdf.parse("May 28, 2013 6:04:38 PM"));
} catch (ParseException e) {
e.printStackTrace();
}
}

错误:

java.text.ParseException: Unparseable date: "May 28, 2013 6:04:38 PM"
at java.text.DateFormat.parse(DateFormat.java:377)
at com.test(DateUtil.java:71)

最佳答案

试试这个:

        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MMMM d, y h:mm:ss a");
String datestr = "May 28, 2013 1:04:38 PM";
LocalDateTime dateTime = LocalDateTime.parse(datestr, dtf);
System.out.println(dateTime.format(dtf));

关于java - "May 28, 2013 6:04:38 PM"是什么格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61066939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com