gpt4 book ai didi

java - 如何在 Java 中格式化非纯日期?

转载 作者:行者123 更新时间:2023-11-29 06:57:10 24 4
gpt4 key购买 nike

<分区>

我有两个日期需要格式化,但我收到以下异常。我的主要问题是白天部分的 th rd etc。我找不到这个问题的任何答案。我检查了所有这些链接 1 , 2 , 3 , 4 , 5我想我应该使用正则表达式,但不确定如何使用。

 10th Dec 2019 -> 2019-12-10 
10th December 2019 -> 2019-12-10

代码

 String date1 = "10th Dec 2019";
Date date = new SimpleDateFormat("dd MMMM YYYY").parse(date1);
System.err.println(date);
String date2 = new SimpleDateFormat("yyyy-mm-dd").format(date);
System.err.println(date2);

异常

 Exception in thread "main" java.text.ParseException: Unparseable date: "10th Dec 2019"

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