且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C#在ASP.NET中比较系统DateTime和用户输入DateTime

更新时间:2023-02-20 11:48:08

尝试
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