C# DateTimeOffset Parse(String, IFormatProvider, DateTimeStyles)

Description

DateTimeOffset Parse(String, IFormatProvider, DateTimeStyles) converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified culture-specific format information and formatting style.

Syntax

DateTimeOffset.Parse(String, IFormatProvider, DateTimeStyles) has the following syntax.


public static DateTimeOffset Parse(
  string input,/*  w  ww . j  a v a 2 s.  c  o m*/
  IFormatProvider formatProvider,
  DateTimeStyles styles
)

Parameters

DateTimeOffset.Parse(String, IFormatProvider, DateTimeStyles) has the following parameters.

  • input - A string that contains a date and time to convert.
  • formatProvider - An object that provides culture-specific format information about input.
  • styles - A bitwise combination of enumeration values that indicates the permitted format of input. A typical value to specify is None.

Returns

DateTimeOffset.Parse(String, IFormatProvider, DateTimeStyles) method returns An object that is equivalent to the date and time that is contained in input as specified by formatProvider and styles.

Example

The following example illustrates the Parse(String, IFormatProvider, DateTimeStyles) method.


// w  w w  .j  a va 2  s .co  m
using System;
using System.Globalization;
public class MainClass{
  public static void Main(String[] argv){  
    string dateString = "05/01/2014 6:00:00";
    DateTimeOffset offsetDate = DateTimeOffset.Parse(dateString, null, DateTimeStyles.AssumeLocal);
    Console.WriteLine(offsetDate.ToString());  
    
    offsetDate = DateTimeOffset.Parse(dateString, null, DateTimeStyles.AssumeUniversal);
    Console.WriteLine(offsetDate.ToString());
    
    dateString = "05/01/2014 6:00:00AM +5:00";
    offsetDate = DateTimeOffset.Parse(dateString, null, DateTimeStyles.AdjustToUniversal);
    Console.WriteLine(offsetDate.ToString());

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version