C # DateTime for W3CDTF

I can't find anything on the networks about how to do this, but does anyone know how to format C # DateTime in W3CDTF format?

something like this: 1994-11-05T08:15:30-05:00timezone offset

+3
source share
2 answers

Unfortunately, .NET does not contain a standard format for DateTime that is compatible with W3C (see the specification http://www.w3.org/TR/NOTE-datetime ). A W3C compatible string containing the date and time is very useful as it is the standard format for many technologies such as Sitemaps, PingBack, RSS, etc.

From here

What they recommend AnyValidDateTime.ToUniversalTime().ToString("u").Replace(" ", "T");

+2
source

Use a custom date and time format string .

var formatted = myDateTime.ToString("yyyy-MM-ddTHH:mm:ssK");
+6
source

All Articles