DateTimeOffset::TryParse Method (String^, IFormatProvider^, DateTimeStyles, DateTimeOffset%)
Tries to convert a specified string representation of a date and time to its DateTimeOffset equivalent, and returns a value that indicates whether the conversion succeeded.
Assembly: mscorlib (in mscorlib.dll)
public: static bool TryParse( String^ input, IFormatProvider^ formatProvider, DateTimeStyles styles, [OutAttribute] DateTimeOffset% result )
A string that contains a date and time to convert.
An object that provides culture-specific formatting information about input.
A bitwise combination of enumeration values that indicates the permitted format of input.
When the method returns, contains the DateTimeOffset value equivalent to the date and time of input, if the conversion succeeded, or MinValue, if the conversion failed. The conversion fails if the input parameter is null or does not contain a valid string representation of a date and time. This parameter is passed uninitialized.
Return ValueType: System::Boolean
true if the input parameter is successfully converted; otherwise, false.
This overload of the DateTimeOffset::Parse(String^, IFormatProvider^, DateTimeStyles) method, except that it does not throw an exception if the conversion fails. The method parses a string with three elements that can appear in any order and are delimited by white space. These three elements are shown in the following table.method is like the
Although each of these elements is optional, <Offset> cannot appear by itself. It must be provided together with either <Date> or <Time>. If <Date> is missing, its default value is the current day. If <Date> is present but its year component consists of only two digits, it is converted to a year in the provider parameter's current calendar based on the value of the Calendar::TwoDigitYearMax property. If <Time> is missing, its default value is 12:00:00 AM. If <Offset> is missing, its default value is the offset of the local time zone, or Zero if either the DateTimeStyles::AdjustToUniversal or DateTimeStyles::AssumeUniversal value is specified in styles. If <Offset> is present, it can represent either a negative or a positive offset from Coordinated Universal Time (UTC). In either case, <Offset> must include a sign symbol or the method returns false.
The input string is parsed by using the culture-specific formatting information in a DateTimeFormatInfo object supplied by the formatProvider parameter. The formatProvider parameter can be either of the following:
A CultureInfo object that represents the culture whose formatting is used in input. The DateTimeFormatInfo object returned by the CultureInfo::DateTimeFormat property defines the format that is used in input.
A DateTimeFormatInfo object that defines the format of date and time data.
In addition, each element can be delimited by leading or trailing white space, and the <Date> and <Time> components can include inner white space (such as 6: 00:00). Only the <Offset> component cannot include inner white space.
If provider is null, the CultureInfo object that corresponds to the current culture is used.
The positive or negative sign used in <Offset> must be either + or -. It is not defined by the PositiveSign or NegativeSign properties of the NumberFormatInfo object returned by the formatprovider parameter's NumberFormat property.
The following members of the DateTimeStyles enumeration are supported:
Parses the string represented by input and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the returned object's ToUniversalTime() method.
Although valid, this value is ignored. Inner white space is allowed in the <Date> and <Time> components.
Although valid, this value is ignored. Leading white space is allowed in front of each component in the parsed string.
Although valid, this value is ignored. Trailing white space is allowed in front of each component in the parsed string.
Indicates that, if the input parameter lacks an <Offset> element, the offset of the local time zone should be provided. This is the default behavior of themethod.
Indicates that, if the input parameter lacks an <Offset> element, the UTC offset (00:00) should be provided.
Although valid, this value is ignored and has no effect.
Because the DateTimeOffset structure does not include a Kind property, this value has no effect.
Available since 8
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