.NET DateTime.Parse
You're probably using the wrong culture. The month cannot be 26, so it's not a US timestamp. This works though:
using System;
using System.Globalization;
class Program
{
static void Main(string[] args)
{
DateTime dateTime = DateTime.Parse("26/10/2009 8:47:39 AM",
CultureInfo.GetCultureInfo("en-GB"));
}
}
Parse
takes regional settings (culture of current thread) into account. Therefore, I'd use ParseExact
and specify the correct format explicitly with an invariant culture (or the culture you need, eg. en-US
, for AM/PM).
Parsing strings into DateTime
object is almost always a pain. If you know for certain that they will always have the format as your examples do, this should work:
string input = "26/10/2009 8:00:41 AM";
DateTime dateTime = DateTime.ParseExact(input, "dd/MM/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);