Java dateformat: how to handle “ST”, “nd”, “Rd”, “th”?

How to use some dateformats to parse such strings?

As far as I know, there is nothing in simpledateformat

Solution

Try this

String str = "Wednesday,24th July";
str = str.replaceAll("(\\d\\d)..","$1") + " " + Calendar.getInstance().get(Calendar.YEAR);
Date date = new SimpleDateFormat("EEEE,dd MMMM yyyy",Locale.US).parse(str);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>