在java中解析RSS pubDate到Date对象 [英] Parse RSS pubDate to Date object in java

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

问题描述



RSS提要中的格式如下:
4月24日星期六2010 14:01:00 GMT



目前我有什么:

  DateFormat dateFormat = DateFormat.getInstance(); 
日期pubDate = dateFormat.parse(item.getPubDate()。getText());

但是这个代码会抛出一个ParseException,其中包含消息Unparseable date

解决方案

您可以使用类 SimpleDateFormat

  DateFormat formatter = new SimpleDateFormat(EEE,dd MMM yyyy HH:mm:ss zzz); 
Date date = formatter.parse(Sat,24 Apr 2010 14:01:00 GMT);

此外,对于非英语 Locale ,一定要使用以下用英文解析日期:

  new SimpleDateFormat(EEE,dd MMM yyyy HH:mm:ss zzz,Locale。英语); 


How can I parse a pubDate from a RSS feed to a Date object in java.

The format in the RSS feed: Sat, 24 Apr 2010 14:01:00 GMT

What I have at the moment:

DateFormat dateFormat = DateFormat.getInstance();
Date pubDate = dateFormat.parse(item.getPubDate().getText());

But this code throws an ParseException with the message Unparseable date

解决方案

You can define the date format you are trying to parse, using the class SimpleDateFormat:

DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
Date date = formatter.parse("Sat, 24 Apr 2010 14:01:00 GMT");

Additionally, for non-English Locale's, be sure to use the following when parsing dates in English:

new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);

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

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