C# DateTime Parse(String, IFormatProvider, DateTimeStyles)

Description

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

Syntax

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


public static DateTime Parse(
  string s,//from  w  w  w .j  av a 2 s  . c o m
  IFormatProvider provider,
  DateTimeStyles styles
)

Parameters

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

  • s - A string that contains a date and time to convert.
  • provider - An object that supplies culture-specific formatting information about s.
  • styles - A bitwise combination of the enumeration values that indicates the style elements that can be present in s for the parse operation to succeed, and that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is DateTimeStyles.None.

Returns

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

Example

The following code shows how to use DateTime.Parse(String, IFormatProvider, DateTimeStyles) method.


//ww  w. ja v  a  2 s . c o m
using System;
using System.Globalization;
public class IsLeapYear
{
   public static void Main()
   {
      DateTime dt = DateTime.Parse("2012/09/17", CultureInfo.InvariantCulture,DateTimeStyles.AdjustToUniversal );
      Console.WriteLine(dt);
   }
}

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