如何将具有完整月份名称的字符串日期转换为 Java 中的日期对象?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4583749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 07:04:05 来源:igfitidea点击:
How can I convert a String date with full month names to a Date object in java?
提问by Mridang Agarwalla
How can I convert dates with full month names into a Date object in Java? Here's a sample date that I need to convert: 6 December 2002.
如何将具有完整月份名称的日期转换为 Java 中的 Date 对象?这是我需要转换的示例日期:2002 年 12 月 6 日。
Thanks.
谢谢。
回答by Jigar Joshi
String str = "6 December 2002";
DateFormat formatter = new SimpleDateFormat("dd MMM yyyy");
Date date = (Date)formatter.parse(str);
Must See
必看
回答by FrVaBe
Have a look at SimpleDateFormat
SimpleDateFormat sdf = new SimpleDateFormat("d MMMMM yyyy", Locale.US);
Date d = sdf.parse("6 December 2002");
System.out.println(d);