DateTimeOffset::ParseExact Method (String^, String^, IFormatProvider^)
Converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly.
Assembly: mscorlib (in mscorlib.dll)
public: static DateTimeOffset ParseExact( String^ input, String^ format, IFormatProvider^ formatProvider )
A string that contains a date and time to convert.
A format specifier that defines the expected format of input.
An object that supplies culture-specific formatting information about input.
Return ValueType: System::DateTimeOffset
An object that is equivalent to the date and time that is contained in input as specified by format and formatProvider.
The offset is greater than 14 hours or less than -14 hours.
input is null.
format is null.
input is an empty string ("").
input does not contain a valid string representation of a date and time.
format is an empty string.
The hour component and the AM/PM designator in input do not agree.
The FormatException. In contrast, the DateTimeOffset::Parse(String^, IFormatProvider^) method parses the string representation of a date in any one of the formats recognized by the format provider's DateTimeFormatInfo object. Parse also allows the <Date>, <Time>, and <Offset> elements of the string representation of a date and time to appear in any order.method parses the string representation of a date, which must be in the format defined by the format parameter. It also requires that the <Date>, <Time>, and <Offset> elements of the string representation of a date and time appear in the order specified by format. If the input string does not match this format parameter, the method throws a
The format parameter is a string that contains either a single standard format specifier or one or more custom format specifiers that define the required format of the input parameter. For details about valid formatting codes, see Standard Date and Time Format Strings and Custom Date and Time Format Strings. If format includes the z, zz, or zzz custom format specifiers to indicate that an offset must be present in input, that offset must include either a negative sign or a positive sign. If the sign is missing, the method throws a FormatException.
If format requires that input contain a date but not a time, the resulting DateTimeOffset object is assigned a time of midnight (0:00:00). If format requires that input contain a time but not a date, the resulting DateTimeOffset object is assigned the current date on the local system. If format does not require that input contain an offset, the resulting DateTimeOffset object is assigned the time zone offset of the local system.
The particular date and time symbols and strings used in input are defined by the formatProvider parameter, as is the precise format of input if format is a standard format specifier string. The formatProvider parameter can be either of the following:
A CultureInfo object that represents the culture based on which input is interpreted. The DateTimeFormatInfo object returned by its DateTimeFormat property defines the symbols and formatting in input.
A DateTimeFormatInfo object that defines the format of date and time data.
If formatprovider is null, the CultureInfo object that corresponds to the current culture is used.
Notes to Callers:
In the .NET Framework 4, the ParseExact method throws a FormatException if the string to be parsed contains an hour component and an AM/PM designator that are not in agreement. In the .NET Framework 3.5 and earlier versions, the AM/PM designator is ignored.
Available since 4.5
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1