using System;using System.Globalization; using System.Text.RegularExpressions;
public static void Main()
string dateString = "2010-11-29 17:56:22.000000000 -0800";
DateTimeOffset unixstatdt = new DateTimeOffset();
if (DateTimeOffset.TryParseExact(dateString, "yyyy-MM-dd HH:mm:ss.FFFFFFFFF zzz", CultureInfo.InvariantCulture, DateTimeStyles.None, out unixstatdt))
Console.WriteLine("Worked parsed Unix stat datetime with time zone\n {0}", unixstatdt.ToString ("o"));
Console.WriteLine("Failed to parsed Unix stat datetime");
string LinuxStatCMDpattern = @"(\d{4}-\d{2}-\d{2})\s(\d{2}:\d{2}:\d{2}\.)(\d{7})\d{2}\s ([\+-]\d{4})";
string substitution = @"$1 $2$3 $4";
string input = @"2014-03-30 23:14:47.658210121 -0500";
RegexOptions options = RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace;
Match m = Regex.Match(input, LinuxStatCMDpattern, options);
Regex regex = new Regex(LinuxStatCMDpattern, options);
string result = string.Empty;
result = regex.Replace(input, substitution);
Console.WriteLine("Trimmed " + result);
if (DateTimeOffset.TryParseExact(result, "yyyy-MM-dd HH:mm:ss.FFFFFFF zzz", CultureInfo.InvariantCulture, DateTimeStyles.None, out unixstatdt))
Console.WriteLine("Pass 2: Worked parsed Unix stat datetime with time zone\n {0}", unixstatdt.ToString("o"));
Console.WriteLine("Pass 2: Failed");