Export (0) Print
Expand All

DateTimeOffset.Parse Method (String)

Converts the specified string representation of a date, time, and offset to its DateTimeOffset equivalent.

Namespace:  System
Assemblies:   System.Runtime (in System.Runtime.dll)
  mscorlib (in mscorlib.dll)

static member Parse : 
        input:string -> DateTimeOffset

Parameters

input
Type: System.String

A string that contains a date and time to convert.

Return Value

Type: System.DateTimeOffset
An object that is equivalent to the date and time that is contained in input.

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.

Parse(String) parses a string with three elements that can appear in any order and are delimited by white space. These three elements are as 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 <Date> is present but its year component consists of only two digits, it is converted to a year in the current culture's current calendar based on the value of the Calendar.TwoDigitYearMax property. 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 input string is parsed by using the formatting information in a DateTimeFormatInfo object that is initialized for the current culture. To parse a string that contains designated formatting that does not necessarily correspond to the formatting of the current culture, use the ParseExact method and provide a format specifier.

The following example calls the Parse(String) method to parse several date and time strings. The example includes output from March 22, 2007, on a system whose culture is en-us.

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

.NET Framework

Supported in: 4.6, 4, 3.5 SP1, 3.0 SP1, 2.0 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

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)

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

Show:
© 2014 Microsoft