IIS服务器上的日期问题 [英] date issue on IIS server

查看:113
本文介绍了IIS服务器上的日期问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我将网站部署在IIS服务器中. IIS服务器中有一个问题,当我单击注销"按钮时插入用户的登录/注销时间时,它存储日期时间,如14/8/2012,但是当我从IIS浏览网站时,它存储日期时间像; 2012年8月14日.

因此,数据库中存储了两个不同的值,因此无法按日期查看用户的日志.因为在ajax日历中,我将格式设置为14/8/2012.


I deploy the website in IIS server. There is a problem in IIS server that is when I insert the sign in/out time of user when log out button is clicked, it stores the date time like 14/8/2012 but when I browse the website from IIS it stores the date time like ;14-8-2012.

So there are two different values stored in the database and from that I can not view the user`s log by date. Because in ajax calendar I set the format like 14/8/2012.

Class1.sign_out=System.Convert.ToString(DateTime.Now);
                string s = "insert into User_log values('" + Session["user"].ToString() + "','" +string.Format("{0:dd/MM/YYYY}",Class1.sign_in)+ "','" + string.Format("{0:dd/MM/YYYY}",Class1.sign_out)+"'";
                SqlCommand cmd = new SqlCommand(s, c.getcon());
                cmd.ExecuteNonQuery();



所以请帮帮我.
密特什



So please help me.
Mitesh

推荐答案

我认为根本问题是您使用字符数据类型存储日期.我建议不要这样做,而是使用datetime.

另一件事是,您将SQL语句的值连接为语句中的文字.为了防止数据类型转换等问题,请使用 SqlParameter [而是 ^ ]代替
I think the root problem is that you use character data types for storing dates. I would advice not to do that, instead use datetime.

Another thing is that you concatenate the values for the SQL statement as literals in the statement. In order to prevent problems with data type conversions etc. use SqlParameter[^] instead


在C#中需要在以下两种情况下显式定义日期时间格式的情况
1.将日期时间转换为字符串(在这种情况下)
2.将字符串转换为日期时间.

因此,将第一行如下所示.

Class1.sign_out = System.Convert.ToString(DateTime.Now,新的System.Globalization.DateTimeFormatInfo(){ShortDatePattern ="dd/MM/yyyy"});
in C# whenever you need to explicitly define datetime format in following two cases
1. converting a datetime into string (that is ur case)
2. converting a string into date time.

so write the first line as below .

Class1.sign_out=System.Convert.ToString(DateTime.Now, new System.Globalization.DateTimeFormatInfo() { ShortDatePattern = "dd/MM/yyyy" });


这篇关于IIS服务器上的日期问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆