时间问题 [英] Time Problem

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

问题描述

我认为这很简单,结果证明不是。


我有三个变量。 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:03PM

Actiontime
JobStreamStart (11:00:00PM)
JobStreamEnd (2:00:00AM)

If (Format(CDate(ActionTime), "t") >= JobStreamStart AND
(Format(CDate(ActionTime), "t") < jobstreamend Then

Do these actions

End If

Does not work. I am having a problem after midnight when it seems 4AM is
still not available for running. Does anyone have a suggestion?

推荐答案



" scorpion53061"< ad *** @ nospamherekjmsolutions.com>写在留言中

news :ON ************** @ TK2MSFTNGP14.phx.gbl ...

"scorpion53061" <ad***@nospamherekjmsolutions.com> wrote in message
news:ON**************@TK2MSFTNGP14.phx.gbl...
我认为这很简单,结果证明不是。

我有三个变量。动作时间的格式为08/11/2004 11:03 PM

动作时间
JobStreamStart(11:00:00 PM)
JobS treamEnd(凌晨2:00)

如果(格式(CDate(ActionTime)," t")> = JobStreamStart AND
(格式(CDate(ActionTime),t ;)< jobstreamend然后

做这些行动

结束如果

不起作用。我在午夜过后遇到问题,因为它似乎仍然无法运行凌晨4点。有没有人有建议?
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:03PM

Actiontime
JobStreamStart (11:00:00PM)
JobStreamEnd (2:00:00AM)

If (Format(CDate(ActionTime), "t") >= JobStreamStart AND
(Format(CDate(ActionTime), "t") < jobstreamend Then

Do these actions

End If

Does not work. I am having a problem after midnight when it seems 4AM is
still 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 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.


在这种情况下,只比较时间值,因为它去了

比较给定日期的时间值;因此,今天晚上11点至凌晨4点,1AM表示不是

。您需要使用日期值 -

8/12/2004凌晨1点是11/11/2004 11PM和8/12/2004 4AM.You应该使用

DateTime.Compare函数来正确比较这些值。


希望有所帮助..

Imran。


" scorpion53061"< ad *** @ nospamherekjmsolutions.com>写在消息中

新闻:Oa ************** @ TK2MSFTNGP11.phx.gbl ...
In that case, only comparing time values wont work since its going to
compare the time values for a given date; so, 1AM for say today is not
between 11PM and 4AM of today. You''ll need to use the date values -
8/12/2004 1AM is between 8/11/2004 11PM and 8/12/2004 4AM.You should use the
DateTime.Compare function to correctly compare such values.

hope that helps..
Imran.

"scorpion53061" <ad***@nospamherekjmsolutions.com> wrote in message
news:Oa**************@TK2MSFTNGP11.phx.gbl...
我的坏我意思是说凌晨1点....

如果说凌晨1点00分它还在运行。

Imran Koradia <无**** @ microsoft.com>在消息中写道
新闻:e0 ************** @ TK2MSFTNGP14.phx.gbl:
My Bad I meant to say 1AM....

If it says 1:00:00AM it still runs.

"Imran Koradia" <no****@microsoft.com> wrote in message
news:e0**************@TK2MSFTNGP14.phx.gbl:
" scorpion53061" <广告*** @ nospamherekjmsolutions.com>在消息中写道
新闻:ON ************** @ TK2MSFTNGP14.phx.gbl ...
"scorpion53061" <ad***@nospamherekjmsolutions.com> wrote in message
news:ON**************@TK2MSFTNGP14.phx.gbl...
>我认为这很容易,结果证明不是。
>
>我有三个变量。 Actiontime的格式为08/11/2004 11:03 PM
>
>行动时间
> JobStreamStart(11:00:00 PM)
> JobStreamEnd(凌晨2:00)
>
>如果(格式(CDate(ActionTime)," t")> = JobStreamStart AND
>(格式(CDate(ActionTime)," t")< jobstreamend则
>
>执行这些操作
>
>结束如果
>
>不起作用。我在午夜过后看到凌晨4点就出现问题了/>>
>仍无法运行。是否有人有建议?
> 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:03PM
>
> Actiontime
> JobStreamStart (11:00:00PM)
> JobStreamEnd (2:00:00AM)
>
> If (Format(CDate(ActionTime), "t") >= JobStreamStart AND
> (Format(CDate(ActionTime), "t") < jobstreamend Then
>
> Do these actions
>
> End If
>
> Does not work. I am having a problem after midnight when it seems 4AM
> is
> still not available for running. Does anyone have a suggestion?



那是因为凌晨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
<私有子测试时间(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("做这些动作..)
结束如果


或修改你的代码:

如果((格式(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.



你可以比较时间值,但如果您的开始时间(JobStreamStart)小于您的结束时间,则需要测试以查看



比较

dim fDoActions as boolean

如果JobStreamStart< = JobStreamEnd

fDoActions =(格式(CDate(ActionTime)," t")> = JobStreamStart AND

(格式(CDate(ActionTime)," t")< jobstreamend

else

fDoActions = not(格式(CDate(ActionTime)," t")< JobStreamStart OR

not(格式( CDate(ActionTime)," t"> = jobStreamEnd执行这些操作

endif

如果fDoActions那么

执行这些操作

Endif


" Imran Koradia" no **** @ microsoft.com>写在留言中

news:uV ************** @ TK2MSFTNGP12.phx.gbl ...
You could compare the just the time values but you would need to test to see
if your start time (JobStreamStart) is less than your end time for one
comparison

dim fDoActions as boolean
If JobStreamStart<=JobStreamEnd
fDoActions=(Format(CDate(ActionTime), "t") >= JobStreamStart AND
(Format(CDate(ActionTime), "t") < jobstreamend
else
fDoActions= not (Format(CDate(ActionTime), "t") < JobStreamStart OR
not (Format(CDate(ActionTime), "t") >= jobStreamEnd Do these actions
endif
If fDoActions Then
Do these actions
Endif

"Imran Koradia" <no****@microsoft.com> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
在这种情况下,只比较时间值,因为它要进行比较给定日期的时间值;因此,今天上午11点到凌晨4点之间的今天是1点。你需要使用日期值 -
8/12/2004 1AM介于两者之间8/11/2004 11PM和8/12/2004 4AM。您应该使用
DateTime.Compare函数来正确比较这些值。

希望有帮助..
Imran 。

scorpion53061"< ad *** @ nospamherekjmsolutions.com>在消息中写道<新闻:Oa ************** @ TK2MSFTNGP11.phx.gbl ...
In that case, only comparing time values wont work since its going to
compare the time values for a given date; so, 1AM for say today is not
between 11PM and 4AM of today. You''ll need to use the date values -
8/12/2004 1AM is between 8/11/2004 11PM and 8/12/2004 4AM.You should use the DateTime.Compare function to correctly compare such values.

hope that helps..
Imran.

"scorpion53061" <ad***@nospamherekjmsolutions.com> wrote in message
news:Oa**************@TK2MSFTNGP11.phx.gbl...
我的坏我想说的是凌晨1点....... />
如果它说凌晨1点00分它仍在运行。

Imran Koradia <无**** @ microsoft.com>在消息中写道
新闻:e0 ************** @ TK2MSFTNGP14.phx.gbl:
My Bad I meant to say 1AM....

If it says 1:00:00AM it still runs.

"Imran Koradia" <no****@microsoft.com> wrote in message
news:e0**************@TK2MSFTNGP14.phx.gbl:
" scorpion53061" <广告*** @ nospamherekjmsolutions.com>在消息中写道
新闻:ON ************** @ TK2MSFTNGP14.phx.gbl ...
>我认为这很容易,结果证明不是。
>
>我有三个变量。 Actiontime的格式为08/11/2004 11:03 PM
>
>行动时间
> JobStreamStart(11:00:00 PM)
> JobStreamEnd(凌晨2:00)
>
>如果(格式(CDate(ActionTime)," t")> = JobStreamStart AND
>(格式(CDate(ActionTime)," t")< jobstreamend则
>
>执行这些操作
>
>结束如果
>
>不起作用。我在午夜过后看到凌晨4点就出现问题了/>>
>仍然无法运行。是否有人有建议?

那是因为凌晨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

私有子测试时间(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("做这些动作..)
结束如果


或修改你的代码:

如果((格式(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。
"scorpion53061" <ad***@nospamherekjmsolutions.com> wrote in message
news:ON**************@TK2MSFTNGP14.phx.gbl...
> 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:03PM
>
> Actiontime
> JobStreamStart (11:00:00PM)
> JobStreamEnd (2:00:00AM)
>
> If (Format(CDate(ActionTime), "t") >= JobStreamStart AND
> (Format(CDate(ActionTime), "t") < jobstreamend Then
>
> Do these actions
>
> End If
>
> Does not work. I am having a problem after midnight when it seems 4AM
> is
> still not available for running. Does anyone have a suggestion?

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.




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

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