DateTime.Parse(str).Month.ToString("0#");

解决方案 »

  1.   

    try
        {
           System.Convert.ToInt32(GetDate.Substring(6, 2));
         }
    catch
         {
           GetDate = GetDate.Substring(6, 1);
         }
      

  2.   

    string sts = "2006-9-6 15:02:14";
    DateTime dt = DateTime.ParseExact(sts, "yyyy-MM-dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo);
    int month = dt.Month;
    int year  = dt.Year;
      

  3.   

    如果能确定格式是确定的,那么也可以把字符串Split后取字符串数组的第二个。
      

  4.   

    时间的Month属性就是整数,可以比较吧
      

  5.   

    string str = "1983-10-24 10:24:25";
    string[] str1 = str.Split(' ');
    string [] str2 = s[0].Split('-');
    现在str2[0]的值为1983 str2[1]的值为10 str2[2]的值为24