Parse string to DateTime by using culture-specific format and formatting style in CSharp

Description

The following code shows how to parse string to DateTime by using culture-specific format and formatting style.

Example


/* w w w .  j a va  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 »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var