如何使用C#在ASP.NET中比较系统DateTime和用户输入DateTime [英] How To Compare system DateTime and user input DateTime in asp.net with c#

查看:137
本文介绍了如何使用C#在ASP.NET中比较系统DateTime和用户输入DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

对asp.net应用程序的怀疑,

系统日期时间,并从用户(文本框)输入日期时间."

如何在asp.net c#中比较这两个日期时间.

i. System.DateTime ="2011-12-02 16:01:52.000";
ii. UserDateaTime ="2010-12-02 16:01:52.000";



条件:如果文本框日期未超过系统日期时间)
1.条件为真,消息通过您的日期是过去或今天.";

2.否则通过您的日期时间是将来的日期"消息发送消息.


错误:运算符<"不能应用于类型为"System.Web.UI.WebControls.Label
"的操作数

给我解决方法.

通过mohan

dear one,

One Doubt for asp.net applications,

"System datetime and entering datetime from user(textBox)."

How to Compare These Two date Time in asp.net c#.

i. System.DateTime="2011-12-02 16:01:52.000";
ii. UserDateaTime="2010-12-02 16:01:52.000";



Condition: if Textbox date is not exceeds for System datetime)
1. Condition True, Message Through "Ur Date is past or today.";

2. Otherwise Message Through "Ur date time is Future Date."


Error: Operator ''<'' cannot be applied to operands of type ''System.Web.UI.WebControls.Label

give me solution.

By mohan

推荐答案

尝试
DateTime.Compare方法 [ ^ ]将比较两个DateTime实例,并返回一个整数,该整数指示第一个实例是否早于,相同或晚于第二个实例.
或尝试
http://forums.asp.net/t/1025431.aspx/1 [ ^ ]
Try
DateTime.Compare Method[^] which will Compares two instances of DateTime and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance.
or try
http://forums.asp.net/t/1025431.aspx/1[^]


protected void Button1_Click(object sender, EventArgs e)
    {
        string dt1 = DateTime.Now.ToString("MM/dd/yyyy");
        string dt2 = TextBox1.Text;
        if (dt1 == dt2)
        {
            TextBox1.Text = "Correct";
        }
        else TextBox1.Text = "Wrong";
    }




尝试一下..并建议您的终端MM/dd/yyyy formate ..




try it..and advice your end MM/dd/yyyy formate ..


您可以使用DateTime.Compare方法或比较ajax验证的验证器.或通过删除:"或"/"将其转换为Int64,然后比较这些值.

最好的问候,
爱德华
You can use the DateTime.Compare method or compare validator of ajax validation. Or convert it to Int64 by removing the ":" or "/" then compare the values.

Best regards,
Eduard


这篇关于如何使用C#在ASP.NET中比较系统DateTime和用户输入DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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