I’m currently creating an app to manage RSS feeds. Because there is no one set standard for the publication date of a post (there is, but for whatever reason a lot of feeds don’t follow it), I have multiple different types of date strings to parse.
I can parse these types of dates:
Thu, 01 Jan 1970 00:00:00 +0000
However, the date format used on NASA’s Breaking News feed resembles something like:
Thu, 01 Jan 1970 00:00 GMT
JavaScript’s date parser can easily parse both of these types, but I just can’t find a solution to this in Dart. I tried using the HttpDate
parser, which is the most similar to this type, but it fails because there is no indicator of seconds in the format. I’m also worried that there are other date format types that I don’t know about that JavaScript can parse, but Dart can’t. What should I do?
2
Answers
Here i use the INTL package to stablish two patterns, then i make a function to try to parse a date trying each of the patterns, if it fails to do so it throws an exception
you can use timezone to convert DateTime To TZDateTime