日期比较不适用于IIS [英] Date comparision not working on IIS

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

问题描述

我在txtDate文本框的文本更改事件上编写了以下代码。

I have written the following code on text change event of txtDate textbox.

DateTime dt1 = DateTime.Parse(txtVrDate.Text.Trim()).Date;
DateTime dt2 = DateTime.Now.Date;

if ((dt2 - dt1).Days > 2)
{

    ScriptManager.RegisterStartupScript(this, typeof(string), "myalert", "alert('InValid Date');", true);
    txtDate.Text = DateTime.Parse(DateTime.Now.ToShortDateString()).ToString("dd/MM/yyyy");
    txtDate.Focus();
}



它在本地asp.net开发服务器上工作,但在IIS上发布时它不验证textbox。我无法弄清楚问题是什么。

请帮帮....



提前感谢...


Its working on local asp.net development server but when published on IIS it does not validate textbox.I m not able to figure out whats the problem.
Please help....

thanks in advance...

推荐答案

可能是用户输入或本地化问题:DateTime.Parse使用它运行的PC的区域设置 - 这将是您的PC用于开发,但将是用于生产的托管PC。在物理上运行IIS的计算机将确定它所设置的语言环境,以及它所期望的日期/时间格式 - 这可能与客户日期/时间格式不同。



最好的解决方案是不使用文本框进行日期输入:有一个Calendar控件(或各种类似的)可以做得更好,但它以客户端格式显示数据,并返回DateTime值直接到您的代码。
Probably, it either user input or a localization problem: DateTime.Parse uses the locale of the PC it is running on - which will be your PC for development, but will be the hosting PC for production. Where the computer running IIS is located physically will determine what locale it is set for, and thus what date/time format it expects - this may not be the same as the client date/time format.

The best solution is to not use text boxes for date inputs: there is a Calendar control (or various similar) which does a better job, but which presents data in the client format, and returns a DateTime value directly to your code.


这篇关于日期比较不适用于IIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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