I receive some file from external system, the date/time is represented as 28/Jul/2015:01:02:36 -0500.
What is the best way to parse it in to DateTime type in C#?
You should look here for more information on Custom Date Formats in C#:
However here is some code to get you started.
First, determine the correct format string you expect. and then use ParseExact
static void Main(string[] args)
{
var date = "28/Jul/2015:01:02:36 -0500";
var formatstring = "dd/MMM/yyyy:HH:mm:ss K";
var d = DateTime.ParseExact(date, formatstring, null);
Console.WriteLine(d);
Console.ReadLine();
}
Hope this helps!
DateTimeOffsetinstead ofDateTime. Especially if-05:00is not an offset in your time zone.