day1=strs[1].ToString ();
        NowDay =DateTime.Now.ToString();
        if(DateTime .Compare(Convert.ToDateTime(NowDay), Convert.ToDateTime (day1))>=0)可是老是提示我:该字符串未被识别为有效的 DateTime。有一个从索引 0 处开始的未知字

解决方案 »

  1.   

    变量day1中的内容不对吧,跟踪一下看看..
      

  2.   

    day1 是不是日期的格式呀?
      

  3.   

    将  day1 转换成时间格式
      

  4.   

    strs[1]的值肯定有问题.不符合转换条件.如:20081011;2005-10-11,2008/10/11,10/11/2008
    这些都可以.条件宽松.但不能是abkdfj这样的.看看你的strs[1]的直吧.
      

  5.   

    day1不是DateTime(时间)类型的吧!lz
      

  6.   

    问题还是没有搞定呀,贴出来大家看
    <%@ Application Language="C#" %>
    <%@Import Namespace ="System.IO" %><script runat="server">    void Application_Start(object sender, EventArgs e) 
        {
            // 在应用程序启动时运行的代码
            Application["count"] = 0;
            Application["day"] = DateTime.Now.ToString ();    }
        
        void Application_End(object sender, EventArgs e) 
        {
            //  在应用程序关闭时运行的代码
     
        }
            
        void Application_Error(object sender, EventArgs e) 
        { 
            // 在出现未处理的错误时运行的代码    }    void Session_Start(object sender, EventArgs e) 
        {
            // 在新会话启动时运行的代码
            Application.Lock();
            int count = 0;
            string str="";
            DateTime  NowDay;
            DateTime  day1;
            StreamReader sr;
            string filePath = Server.MapPath("count.txt");
            sr = File.OpenText(filePath);
            while (sr.Peek() != -1)
            {
                str = sr.ReadLine();
            }
            sr.Close();
            string strs=str.Split (',').ToString ();
            count=Convert.ToInt32(strs[0]);
            day1 =Convert.ToDateTime ( strs[1].ToString ()) ;
            NowDay = DateTime.Now;
           if(DateTime .Compare(Convert.ToDateTime(NowDay), Convert.ToDateTime (day1))>=0)
            {
                count=0;
                day1=DateTime.Now .AddDays (1).ToShortDateString ()+""+"00:00:00";
                string NewDayStr="0"+","+day1.ToString();
                StreamWriter sw=new StreamWriter (filePath ,false);
                sw.WriteLine (NewDayStr);
                sw.Close ();
            }
            object objcount=count;
            object objday=day1;
            Application ["count"]=objcount ;
            Application ["day1"]=objday ;
            int stats=0;
            stats=(int)Application ["count"];
            stats+=1;
            object obj=stats ;
            Application ["count"]=obj;
            string day0=(string)Application ["day"];
            string str0=obj .ToString ()+","+day0.ToString();
            StreamWriter sw1=new StreamWriter (filePath ,false);
            sw1.WriteLine (str0);
            sw1 .Close ();
            Application .UnLock ();
            
        }    void Session_End(object sender, EventArgs e) 
        {
            // 在会话结束时运行的代码。 
            // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
            // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer 
            // 或 SQLServer,则不会引发该事件。
            int stat = 0;
            stat=(int)Application["count"];
            string day0=(string)Application ["day"];
            string str=stat.ToString ()+","+day0 .ToString ();
            string filePath=Server .MapPath ("count.txt");
            StreamWriter sw=new StreamWriter (filePath ,false);
            sw.WriteLine (str);
            sw.Close ();
        }
           
    </script>
      

  7.   

    day1=DateTime.Now .AddDays (1).ToShortDateString ()+""+"00:00:00"; 
    改成day1=DateTime.Now.AddDays (1).ToShortDateString()+" "+"00:00:00"; 
      

  8.   

    day1=DateTime.Now .AddDays (1).ToShortDateString ()+""+"00:00:00"; 改成
    day1 = DateTime.Now.AddDays(1).Date.ToLongDateString();