Ntohing_Trolll Ntohing_Trolll - 28 days ago 6
Vb.net Question

is timeofday.tostring("hh:mm:ss") in a specified range,and if it is not in range returning a false boolean value else a true boolean value

Dim time As String = TimeOfDay.ToString("tt")
Dim time2 As Integer = TimeOfDay.ToString("hh:mm:ss")
If time = ("du.") Then
timehre = (time2 + 12)
Debug.WriteLine("munkaidoben")
Else
Debug.Write("munkaidoben = false")
timehre = time
End If

For munkaido As Integer = 13 To 19

If time2.ToString.Contains(munkaido) Then
duplaar = False
Else
duplaar = True
End If
Next


Timehre is already declared as integrer.So,what i want,to get time in utc +1,and if time is in range of 13:00 - 19:00 then return a true boolean value,and if it is not in range of 13:00 - 19:00 then returning a false boolean value.

P.s. sorry for bad english,i hope you will understang my question.

Answer

First, turn on Option Strict:

Dim time2 As Integer = TimeOfDay.ToString("hh:mm:ss")
...
For munkaido As Integer = 13 To 19
    If time2.ToString.Contains(munkaido) Then

That code will not compile because you are assigning a string to an integer, and a string can never contain an integer.

Your code is not really testing if the time is in a range, just whether 13-19 appear somewhere in the string. If the minutes or seconds are one of those values, it will validate.

Dont use strings to do DateTime operations. The DateTime type has a full set of properties you can use:

Dim dt = DateTime.Now

If dt.Hour >= 13 AndAlso dt.Hour <= 19 Then 
    Return True
Else
    Return False
End If

I am not sure how UTC comes into play, but that is also easy using DateTime methods:

Dim dt = DateTime.Now.ToUniversalTime()

To add an hour:

Dim dt = DateTime.Now.ToUniversalTime.AddHours(1)