using System;
using System.Globalization;
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
string[] formats ={
"MM/dd/yyyy HH:mm:ss tt",
"MM/dd/yyyy HH:mm:ss",
"MM/dd/yyyy H:mm:ss tt",
"MM/dd/yyyy H:mm:ss",
"M/dd/yyyy HH:mm:ss tt",
"M/dd/yyyy HH:mm:ss",
"M/dd/yyyy H:mm:ss tt",
"M/dd/yyyy H:mm:ss",
"MM/d/yyyy HH:mm:ss tt",
"MM/d/yyyy HH:mm:ss",
"MM/d/yyyy H:mm:ss tt",
"MM/d/yyyy H:mm:ss",
"M/d/yyyy HH:mm:ss tt",
"M/d/yyyy HH:mm:ss",
"M/d/yyyy H:mm:ss tt",
"M/d/yyyy H:mm:ss"
};
string date1 = "11/08/2008 4:00:49";
DateTime result;
if (DateTime.TryParseExact(date1, formats,
new CultureInfo("en-US"),
DateTimeStyles.None,
out result))
{
DateTime startTime = result;
}
Console.Write(startTime);
}
}
}
please explain me .. why always that if statement returns false ..
Thanx for help and support, Rik,Phillip,Joel and Kent and everyone else ..
You should declare (and initialize)
Outside the IF statement, or
Inside the IF statement.
You can try to change the value of the DateTimeStyles parameter to either AssumeLocal or AssumeUniversal (depending on your needs) to allow for the lack of a time-zone specification.