private void timer_Tick(object sender, EventArgs e)
        {
            label1.Text = DateTime.Now.ToString();    
            int nu = int.Parse(DateTime.Now.Second.ToString().Substring(1, 1));//截取秒的个位数 运行到第三个9秒的时候就会报  
          索引和长度必须引用该字符串内的位置。
          参数名: length   求问这是为什么?
        }

解决方案 »

  1.   

    string s=DateTime.Now.Second.ToString();
    if(s.length>1)
    {
    s=s.Substring(1,1);
    }
      

  2.   

    肯定是Substring(1,   1));这个的问题了,自己看看吧就知道了,
      

  3.   

            int timenow = 0;
            private void timer_Tick(object sender, EventArgs e)
            {
                label1.Text = DateTime.Now.ToString();
                string timesm = DateTime.Now.Second.ToString();
                if (timesm.Length > 1)
                {
                    timenow =Int32.Parse(timesm.Substring(1, 1));
                }
                TimepictureBox.Image = big_maptimes[timenow];//换图
            }
    继续问下,那这样写为什么每次到第三轮了还是会停顿10秒?
      

  4.   

    我知道了,是每次前十秒,length字符串只有 一位,所以没有进循环里面。那这样要怎么解决呢?
      

  5.   

    使用格式化字符串int   nu   =   int.Parse(DateTime.Now.Second.[color=#FF0000ToString("00")][/color].Substring(1, 1));
      

  6.   

    使用格式化字符串int nu = int.Parse(DateTime.Now.Second.ToString("00").Substring(1, 1));
      

  7.   

    int nu=DateTime.Now.Second % 10; 就可以了
    何必要写的这么复杂呢