C# DateTimeOffset Parse(String, IFormatProvider)

Description

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

Syntax

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


public static DateTimeOffset Parse(
  string input,
  IFormatProvider formatProvider
)

Parameters

DateTimeOffset.Parse(String, IFormatProvider) 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.

Returns

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

Example

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.


using System;//from   www . j a  va 2 s . c o  m
using System.Globalization;
public class MainClass{
  public static void Main(String[] argv){  
    DateTimeFormatInfo fmt = new CultureInfo("fr-fr").DateTimeFormat;
    string dateString = "03-12-07";
    DateTimeOffset offsetDate = DateTimeOffset.Parse(dateString, fmt);
    Console.WriteLine("{0} returns {1}", 
                      dateString, 
                      offsetDate.ToString());
    
    dateString = "15/09/07 08:45:00 +1:00";
    offsetDate = DateTimeOffset.Parse(dateString, fmt);
    Console.WriteLine("{0} returns {1}", 
                      dateString, 
                      offsetDate.ToString());
    
    dateString = "mar. 1 janvier 2014 1:00:00 +1:00"; 
    offsetDate = DateTimeOffset.Parse(dateString, fmt);
    Console.WriteLine("{0} returns {1}", 
                      dateString, 
                      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