本文介绍了时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 我认为这很简单,结果证明不是。 我有三个变量。 Actiontime格式为08/11/2004 11:03 PM 行动时间 JobStreamStart(11:00:00 PM) JobStreamEnd (2:00:00 AM) If(格式(CDate(ActionTime)," t")> = JobStreamStart AND (格式(CDate) (ActionTime)," t")< jobstreamend然后 做这些行动 结束如果 不起作用。我在午夜过后遇到问题,似乎早上4点还没有b $ b仍然无法运行。有没有人有建议?What I thought would be pretty easy has turned out not to be.I have three variables. Actiontime is formatted as 08/11/2004 11:03PMActiontimeJobStreamStart (11:00:00PM)JobStreamEnd (2:00:00AM)If (Format(CDate(ActionTime), "t") >= JobStreamStart AND(Format(CDate(ActionTime), "t") < jobstreamend ThenDo these actionsEnd IfDoes not work. I am having a problem after midnight when it seems 4AM isstill not available for running. Does anyone have a suggestion?推荐答案 这是因为凌晨4点不是在晚上11点到凌晨2点之间。这是要走的路: 私有子测试子() Dim ActionTime As DateTime = _ DateTime。 Parse(" 08/11/2004 11:03 PM") testtime(ActionTime) ActionTime = DateTime.Parse(" 08/12/04 04:00 AM" ;) testtime(ActionTime) End Sub 私有子测试时间(ByVal ActionTime As DateTime) Dim StartTime As DateTime = DateTime.Parse(" 08/11/04 11:00 PM") Dim EndTime As DateTime = DateTime.Parse(" 08/12/04 02: 00 AM") If(DateTime.Compare(ActionTime,StartTime)> = 0 AndAlso _ DateTime.Compare(ActionTime,EndTime)< 0)OrElse _ (DateTime.Compare(ActionTime,StartTime)< 0 OrElse _ DateTime.Compare(ActionTime,EndTime)> = 0)然后 MessageBox.Show(执行这些操作......) 结束如果 结束子 或修改你的代码: If((格式(CDate(Ac (时间),t)> = JobStreamStart AndAlso _ (格式(CDate(ActionTime)," t")< jobstreamend))OrElse _ ((格式(CDate(ActionTime)," t")< JobStreamStart OrElse _ (格式(CDate(ActionTime)," t")> = jobstreamend))然后 MessageBox.Show(做这些动作......) 结束如果 希望有所帮助.. Imran。That''s because 4 AM is not between 11PM and 2AM. Here''s the way to go:Private Sub testsub()Dim ActionTime As DateTime = _DateTime.Parse("08/11/2004 11:03PM")testtime(ActionTime)ActionTime = DateTime.Parse("08/12/04 04:00AM")testtime(ActionTime)End SubPrivate Sub testtime(ByVal ActionTime As DateTime)Dim StartTime As DateTime = DateTime.Parse("08/11/04 11:00PM")Dim EndTime As DateTime = DateTime.Parse("08/12/04 02:00AM")If (DateTime.Compare(ActionTime, StartTime) >= 0 AndAlso _DateTime.Compare(ActionTime, EndTime) < 0) OrElse _(DateTime.Compare(ActionTime, StartTime) < 0 OrElse _DateTime.Compare(ActionTime, EndTime) >= 0) ThenMessageBox.Show("Do These Actions..")End IfEnd Subor modifying your code:If ((Format(CDate(ActionTime), "t") >= JobStreamStart AndAlso _(Format(CDate(ActionTime), "t") < jobstreamend)) OrElse _((Format(CDate(ActionTime), "t") < JobStreamStart OrElse _(Format(CDate(ActionTime), "t") >= jobstreamend)) ThenMessageBox.Show("Do These Actions..")End Ifhope that helps..Imran. 那是因为凌晨4点不是在晚上11点到凌晨2点之间。这是要走的路: Private Sub testsub() Dim ActionTime As DateTime = _ DateTime.Parse(" 08/11/2004 11:03 PM" ) testtime(ActionTime) ActionTime = DateTime.Parse(" 08/12/04 04:00 AM") testtime(ActionTime) End Sub Dim StartTime As DateTime = DateTime.Parse(" 08/11/04 11:00 PM") Dim EndTime As DateTime = DateTime.Parse( 08/12/04 02:00 AM ") If(DateTime.Compare(ActionTime,StartTime)> = 0 AndAlso _ DateTime.Compare(ActionTime,EndTime)< 0)OrElse _ (DateTime.Compare(ActionTime,StartTime)< 0 OrElse _ DateTime.Compare(ActionTime,EndTime)> = 0)然后 MessageBox.Show("做这些动作..)结束如果 或修改你的代码: 如果((格式(CDate(ActionTime)) ,t,> = JobStreamStart AndAlso _ (格式(CDate(ActionTime)," t")< jobstreamend))OrElse _ ((格式(CDate(ActionTime),& ; t")< JobStreamStart OrElse _ (格式(CDate(ActionTime)," t")> = jobstreamend))然后 MessageBox.Show(" Do These Actions .." )结束如果 希望有帮助.. Imran。 That''s because 4 AM is not between 11PM and 2AM. Here''s the way to go: Private Sub testsub() Dim ActionTime As DateTime = _ DateTime.Parse("08/11/2004 11:03PM") testtime(ActionTime) ActionTime = DateTime.Parse("08/12/04 04:00AM") testtime(ActionTime) End Sub Private Sub testtime(ByVal ActionTime As DateTime) Dim StartTime As DateTime = DateTime.Parse("08/11/04 11:00PM") Dim EndTime As DateTime = DateTime.Parse("08/12/04 02:00AM") If (DateTime.Compare(ActionTime, StartTime) >= 0 AndAlso _ DateTime.Compare(ActionTime, EndTime) < 0) OrElse _ (DateTime.Compare(ActionTime, StartTime) < 0 OrElse _ DateTime.Compare(ActionTime, EndTime) >= 0) Then MessageBox.Show("Do These Actions..") End If End Sub or modifying your code: If ((Format(CDate(ActionTime), "t") >= JobStreamStart AndAlso _ (Format(CDate(ActionTime), "t") < jobstreamend)) OrElse _ ((Format(CDate(ActionTime), "t") < JobStreamStart OrElse _ (Format(CDate(ActionTime), "t") >= jobstreamend)) Then MessageBox.Show("Do These Actions..") End If hope that helps.. Imran. 这篇关于时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-07 17:46