Java DateFormat:如何处理"st","nd","rd","th"? [英] Java DateFormat: How to deal with "st", "nd", "rd", "th"?

查看:107
本文介绍了Java DateFormat:如何处理"st","nd","rd","th"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用某些DateFormat解析这样的字符串?

How can I parse a string like this using some DateFormat?

7月24日,星期三

Wednesday, 24th July

据我所知, SimpleDateFormat 中没有任何内容.

As far as I can tell there's nothing in SimpleDateFormat.

推荐答案

尝试一下

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);

这篇关于Java DateFormat:如何处理"st","nd","rd","th"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆