2016-07-05 19 views
1

文字列として読み込みを条件付けしようとしていますが、VBScriptを使用して指定された時間間隔の間にあります。スクリプトは次のとおりです。vbscriptでの時間間隔の時間

dim splitString, currentTime 
splitString = Split("12 59 00") 
currentTime = TimeSerial(splitString(0),splitString(1), splitString(2)) 
If ((DateAdd("n",-1,time())) <= currentTime < DateAdd("n", 1,time())) Then 
    Wscript.Echo currentTime 
End If 

これは機能していないようです。現在時刻が時間間隔外であってもエコーを取得する。あなたがチェックすることができPython

+0

これは、前もって、ある形式か別の形式で質問されているはずです。 – Lankymart

答えて

2

は「区間である」短い

if x <= y < z: 
    ... 

を使用しますが、VBScriptで、あなたが独立して、両方の条件を評価する必要が長く

If x <= y And y < z Then 
    ... 
2

を必要としています。

dim splitString, currentTime 
splitString = Split("3 39 00") 
currentTime = TimeSerial(splitString(0),splitString(1), splitString(2)) 
If (DateAdd("n",-1,time()) <= currentTime) And (currentTime < DateAdd("n", 1,time())) Then 
    Wscript.Echo currentTime 
End If 
2

私はDateDiffを使用しました。 IF文を次のように変更しました。

If (DateDiff("n",DateAdd("n",-1,time()),currentTime) = 1 AND DateDiff("n",currentTime,DateAdd("n",1,time())) = 1) Then 
    Wscript.Echo currentTime 
End If 

期待どおりに機能しました。