Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting DateTime as RFC-3339 for RSS Feed

When I print my DateTime with myDate.toIso8601String();

it prints

2015-11-15T11:55:32.250

Which doesn't validate with an online validator I tried. The spec says it should be of one of the following formats:

2002-10-02T10:00:00-05:00

2002-10-02T15:00:00Z

2002-10-02T15:00:00.05Z

I could try adding a Z at the end, but that seems hacky. Is there a way to print a DateTime in Dart so it complies to one of the following formats?

like image 801
Pacane Avatar asked Sep 26 '22 05:09

Pacane


1 Answers

Z is for UTC. You get it if you convert your DateTime to an UTC time with

new DateTime().now().toUtc().toIso8601String();

Try it in DartPad

like image 162
Günter Zöchbauer Avatar answered Oct 03 '22 06:10

Günter Zöchbauer