我现在有这样一个时间字符串:"Sat May 21 15:37:17 +0800 2011"怎么转化为时间

解决方案 »

  1.   


                string str = "Sat May 21 15:37:17 +0800 2011";
                DateTime dt = DateTime.ParseExact(str, "ddd MMM dd HH:mm:ss zzzz yyyy", new System.Globalization.CultureInfo("en-us"));
                Console.WriteLine(dt.ToString("yyyy-MM-dd HH:mm:ss"));
      

  2.   

    string xx = "Thu Jul 28 10:00:00 UTC+0800 2005";
      string[] cx = xx.Split(' ');
      System.Globalization.DateTimeFormatInfo g = new System.Globalization.DateTimeFormatInfo();
      g.LongDatePattern = "dd MMMM yyyy";
      DateTime DT = DateTime.Parse(string.Format("{0} {1} {2} {3}", cx[2], cx[1], cx[5], cx[3]), g);
      MessageBox.Show(DT.ToString());
      

  3.   

    1楼的方法明显比2楼好。
    2楼正解忽略时区+0800了。放在不是东八区的地方就是个错误。即使在东八区,也存在UTC、Local时间转换的问题。