day1=strs[1].ToString ();
NowDay =DateTime.Now.ToString();
if(DateTime .Compare(Convert.ToDateTime(NowDay), Convert.ToDateTime (day1))>=0)可是老是提示我:该字符串未被识别为有效的 DateTime。有一个从索引 0 处开始的未知字
NowDay =DateTime.Now.ToString();
if(DateTime .Compare(Convert.ToDateTime(NowDay), Convert.ToDateTime (day1))>=0)可是老是提示我:该字符串未被识别为有效的 DateTime。有一个从索引 0 处开始的未知字
解决方案 »
- vs2005启动调试路径问题,不要有程序目录名,快疯掉了
- 用UrlRewriter.dll实现伪静态后在服务器不能运行出现404错误
- 请教在数组中查找前后相邻的两个数
- 关于jquery thickbox 的问题 !!!
- 经常要下载些邮件到本地桌面,保存为HTML文件,按日期设置文件夹,下载文件用标号1,2,3...代替,想做个自动化软件,大家说说思路
- asp.net中引用的javascript文件。
- 类似小偷程序的功能
- 如何远程访问路由器,跪求有使用经验的大侠
- 关于DataGrid中DropDownList的问题???
- 站点集群之间数据同步的问题,求高手解决方案
- Cache 指的是服务器存储还是客户端存储, 如果是服务器存储, 它与session又有多大的区别?
- 如何实现读取客户端IP地址的前三位
这些都可以.条件宽松.但不能是abkdfj这样的.看看你的strs[1]的直吧.
<%@ 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>
改成day1=DateTime.Now.AddDays (1).ToShortDateString()+" "+"00:00:00";
day1 = DateTime.Now.AddDays(1).Date.ToLongDateString();