在 vb.net 中比较时间 [英] Comparing Times in vb.net

查看:89
本文介绍了在 vb.net 中比较时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个不同的 DateTime 框.两个框只显示日期,另外两个只显示时间

I have four different DateTime boxes. Two boxes just displays the Date and the other two just Displays the time

如果当前时间在午夜和早上六点之间,我希望日期框中的日期是前一天.

If the current time is between midnight and six am I want the Date in the date box to be the day before.

我拥有一切,只是缺少比较两者的部分.

I have it all, I'm just missing the part that compares the two.

Dim currentTime As DateTime = Now
        'default date
        If deMaxDate.Value = Nothing Then
            deMaxDate.Value = Now
        End If
        If deMinDate.Value = Nothing Then
            If currentTime.Hour < TimeOfDay.Hour Then
            'THIS IF STATMENT IS WRONG - HOW CAN I CHECK IF ITS BETWEEN 12AM AND 6 HERE
                deMinDate.Value = (Now - TimeSpan.FromDays(1))
            Else
                deMinDate.Value = Now
            End If
        End If
            'default time
            If teMaxTime.Value = Nothing Then
                teMaxTime.Value = Now
            End If
            If teMinTime.Value = Nothing Then
                teMinTime.Value = (Now - TimeSpan.FromHours(6))
            End If

我在第三个 if 语句的评论是我陷入困境的地方.DateTime 是双数据类型吗?就像是如果 currentTime.Hour

My comment by the third if statment is where I'm stuck at. DateTime is a double datatype? Something like if currentTime.Hour < TimeOfDay.Hour.Equals(6) ?

推荐答案

currentTime.Hour

currentTime.Hour < TimeOfDay.Hour.Equals(6)

最终成为答案

这篇关于在 vb.net 中比较时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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