开发者

C# DateTime to W3CDTF

I can't seem to find anything on the nets on how to do this, but does anyone know how to format a C# DateTime in the W3CDTF f开发者_如何学运维ormat?

specifically, something like this: 1994-11-05T08:15:30-05:00 with the timezone offset


Use a custom date and time format string.

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


Unfortunately, .NET does not contain a standard format for the W3C-compliant DateTime (see the specification on http://www.w3.org/TR/NOTE-datetime). W3C-compliant string containing date and time are very useful since this is the standard format for many technologies such as Sitemaps, PingBack, RSS and so on.

From Here

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜