如何在.NET中获取此DateTime格式

Pur*_*ome 1 .net c# datetime .net-4.0

我正在尝试将一些DateTime格式化为此W3C DateTime格式: -

Complete date plus hours and minutes:
eg. YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)

where:
 YYYY = four-digit year
 MM   = two-digit month (01=January, etc.)
 DD   = two-digit day of month (01 through 31)
 hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
 mm   = two digits of minute (00 through 59)
 ss   = two digits of second (00 through 59)
 s    = one or more digits representing a decimal fraction of a second
 TZD  = time zone designator (Z or +hh:mm or -hh:mm)
Run Code Online (Sandbox Code Playgroud)

我原来有这个......

var myDateTime = someDateTime.ToString("s",
    System.Globalization.CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)

但这导致了一串:

2011-08-31T08:46:00
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

Dan*_*rth 5

你想要"o":

var myDateTime = someDateTime.ToString("o",
System.Globalization.CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)