Parse RSS pubDate to Date object in java

后端 未结 3 682
甜味超标
甜味超标 2020-12-04 19:47

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:

相关标签:
3条回答
  • 2020-12-04 20:00

    If you need to have an RFC822 compliant date, try this :

    DateFormat dateFormatterRssPubDate = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
    
    0 讨论(0)
  • 2020-12-04 20:11

    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);
    
    0 讨论(0)
  • 2020-12-04 20:19

    For the lucky one that can use the Java 8 LocalDateTime:

    LocalDateTime localDateTime = LocalDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse("Sat, 24 Apr 2010 14:01:00 GMT"));
    
    0 讨论(0)
提交回复
热议问题