DateTimeOffset::ToString Method (String)
Converts the value of the current DateTimeOffset object to its equivalent string representation using the specified format.
Assembly: mscorlib (in mscorlib.dll)
The length of format is one, and it is not one of the standard format specifier characters defined for DateTimeFormatInfo.
format does not contain a valid custom format pattern.
The date and time is outside the range of dates supported by the calendar used by the current culture.
The format parameter should contain either a single format specifier character (see Standard Date and Time Format Strings) or a custom format pattern (see Custom Date and Time Format Strings) that defines the format of the returned string. If format is a null or empty string (""), the DateTimeOffset value is output using the default format.
Existing format specifier
Designed to round-trip a date and time. With DateTimeOffset, maps to "zzz" (the offset is always displayed with hours and minutes). Note that "K" is a custom format specifier; it cannot appear as the single character in format.
Converts the DateTimeOffset object to Coordinated Universal Time (UTC) and outputs it using the custom format string ddd, dd MMM yyyy HH:mm:ss GMT.
Converts the DateTimeOffset object to UTC and outputs it using the format yyyy-MM-dd HH:mm:ssZ.
The remaining standard date and time format specifiers behave the same with the method as they do with the ToString method.
This method uses formatting information derived from the current culture. For more information, see CurrentCulture.Notes to Callers
The method returns the string representation of the date and time in the calendar used by the current culture. If the value of the current DateTimeOffset instance is earlier than Calendar::MinSupportedDateTime or later than Calendar::MaxSupportedDateTime, the method throws an ArgumentOutOfRangeException. The following example provides an illustration. It attempts to format a date that is outside the range of the HebrewCalendar class when the current culture is Hebrew (Israel).
.NET FrameworkSupported in: 4.5.2, 4.5.1, 4.5, 4, 3.5 SP1, 3.0 SP1, 2.0 SP1
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
.NET for Windows Phone appsSupported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)