c#字符串转datatime时,因操作系统不一致产生的问题解决方法

问题:
Fri, 06 May 11 13:51:33 +0800
转为datatime时使用
DataTime.Parse("Fri, 06 May 11 13:51:33 +0800") 失败
//解决方法如下:
string dateString; 
CultureInfo culture;
 DateTimeStyles styles;
 DateTime dateResult;

  // Parse a date and time with no styles. 
dateString = "03/01/2009 10:00 AM";
 culture = CultureInfo.CreateSpecificCulture("en-US");
 styles = DateTimeStyles.None; 
if (DateTime.TryParse(dateString, culture, styles, out dateResult))   
 Console.WriteLine("{0} converted to {1} {2}.",           
            dateString, dateResult, dateResult.Kind); 
else  
  Console.WriteLine("Unable to convert {0} to a date and time."
 dateString);

你可能感兴趣的:(操作系统)