Export (0) Print
Expand All

DateTimeOffset.Parse Method (String, IFormatProvider)

Converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified culture-specific format information.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static function Parse(
	input : String, 
	formatProvider : IFormatProvider
) : DateTimeOffset

Parameters

input
Type: System.String

A string that contains a date and time to convert.

formatProvider
Type: System.IFormatProvider

An IFormatProvider object that provides culture-specific format information about input.

Return Value

Type: System.DateTimeOffset
A DateTimeOffset equivalent to the date and time that is contained in input as specified by formatProvider.

ExceptionCondition
ArgumentException

The offset is greater than 14 hours or less than -14 hours.

ArgumentNullException

input is a null reference (Nothing in Visual Basic).

FormatException

input does not contain a valid string representation of a date and time.

-or-

input contains the string representation of an offset value without a date or time.

This 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.

Element

Example

<Date>

"2/10/2007"

<Time>

"1:02:03 PM"

<Offset>

"-7:30:15"

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 <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. <Offset> can represent either a negative or a positive offset from Coordinated Universal Time (UTC). In either case, <Offset> must include a sign symbol.

The format of these three elements is defined by the formatProvider parameter, which can be either of the following:

If formatprovider is a null reference (Nothing in Visual Basic), the CultureInfo object that corresponds to the current culture is used. Specific valid formats for date and time elements are defined by the members of the string array returned by the DateTimeFormatInfo.GetAllDateTimePatterns() method.

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 of the formatProvider parameter.

The following example parses date and time strings that are formatted for the fr-fr culture and displays them using the local system's default en-us culture.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1, 3.0 SP1, 2.0 SP1

Community Additions

ADD
Show:
© 2015 Microsoft