日期和时间验证 [英] date and time validation

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

问题描述

hi,在vb.net编码中是否有可能使用两个日期时间选择器来验证日期和时间?

编辑



hi , is there any possibility to validate date and time with two date time pickers in vb.net coding

EDIT



Dim date1 As Date = Me.DateTimePicker2.Value
        Dim date2 As Date = Me.DateTimePicker3.Value

        If (Me.DateTimePicker3.Value <= Me.DateTimePicker2.Value) Then
            TextBox9.Text = "ON-TIME"
        ElseIf (Me.DateTimePicker3.Value > Me.DateTimePicker2.Value) Then
            TextBox9.Text = "DELAY"
        End If




在这里,我通过将datetimepicker自定义格式设置为"MMM dd,yyyy hh:mm:ss tt"来验证日期并立即在文本框中显示状态.我还需要验证时间....




here i validate the date and display the status in the textbox now by setting the datetimepicker customformat to "MMM dd, yyyy hh:mm:ss tt " i need to validate the time also....

推荐答案

使用日期时间选择器输入的时间始终有效.没有要验证的内容.



另请参阅对以上问题的评论中的讨论.我尝试解释DateTime的含义.这不是日期+时间,实际上是时间,是时间线上的唯一点.比较值(``=='',``!='',``< ='',``> ='',``>'',``<'')哪些事件是同时发生的,或者哪个事件随后发生;无需担心数据或一天中的时间.这就是用于时间数据验证的内容.

—SA
The time entered with a date-time picker is always valid. There is nothing to validate.



Please also see the discussion in comments to the question above. I try to explain the meaning of DateTime. This is not date + time, this is actually time, a unique point on the time line. Comparison of the values (''=='', ''!='', ''<='', ''>='', ''>'', ''<'') compares which events are simultaneous or which one follows which one; without data or time of the day concerns. This is what should be used for validation of time data.

—SA


上面提供的所有代码中,您要相互对两个Date值进行求和.为此,您可以使用:
Whatever code provided you above in that you are compairing two Date values with each other.For that you can use :
Dim d1 As DateTime = New DateTime(Year, Month, Day, Hour, Minute, Second)
Dim d2 As DateTime = New DateTime(Year, Month, Day, Hour, Minute, Second)
MessageBox.Show(DateTime.Compare(d1, d2))


如果d1小于d2,则返回-1;如果d1大于d2,则返回1;如果两者相等,则返回0.


It return -1 if d1 is less than d2,1 if d1 is greater than d2 and 0 if both are equal.


这篇关于日期和时间验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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