DateTime.TryParseExact() Method Example

Kundnani.Rt
Posted by Kundnani.Rt under C# category on | Points: 40 | Views : 6842
Following code demonstrates how to use
DateTime.TryparseExact() 
Method.

static void Main(string[] args)
{
string myDateString = "Sat 16 Jun 8:30 AM 2012";
string myDateFormat = "ddd dd MMM h:mm tt yyyy";
DateTime outputDateTime;
if (DateTime.TryParseExact(myDateString, myDateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out outputDateTime))
{
Console.WriteLine(outputDateTime);
}
else
{
Console.WriteLine("Conversion Failed...");
}
Console.Read();
}

Comments or Responses

Login to post response