Skip to content

Instantly share code, notes, and snippets.

@robertgreiner
Created January 14, 2010 20:08
Show Gist options
  • Save robertgreiner/277446 to your computer and use it in GitHub Desktop.
Save robertgreiner/277446 to your computer and use it in GitHub Desktop.
using System;
using System.Text;
using System.Globalization;
namespace TimeManager{
class ParseDate{
static void Main(string[] args) {
/* Take a date in string format, and convert it to a DateTime object
This can be useful for parsing log files with unique date formats. */
CultureInfo provider = CultureInfo.InvariantCulture;
string dateString = "Jan 14 14:11:25 2010";
string format = "MMM dd HH':'mm':'ss yyyy";
DateTime result = DateTime.ParseExact(dateString, format, provider);
Console.WriteLine(result.ToShortDateString() + " " + result.ToShortTimeString());
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment