在Java中解析日期? [英] Parsing a date in Java?

查看:142
本文介绍了在Java中解析日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日期格式为dd-mmm-yy或d-mmm-y,其中月份为字母缩写(例如,09年11月4日或12月12日等) )
我想解析它来生成一个java.util.Date对象。

I have dates in text format of the form dd-mmm-yy or d-mmm-y, where months are abbreviations in letters (for example, 4-Nov-09 or 12-Dec-05, etc...) I would like to parse it to produce a java.util.Date object.

这可以通过利用java.text.DateFormat类来实现吗?或者还有另一个简单的方法呢?

Could this be achieved by leveraging the java.text.DateFormat class? Or is there another easy way of doing this?

推荐答案

您可能需要使用SimpleDateFormat来解析自定义格式。这个文章解释了格式的细节。

You may need to use the SimpleDateFormat for parsing custom formats. This article explains the details of formatting.

"d-MMM-yyyy" corresponds to 4-Nov-2009

这篇关于在Java中解析日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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