Private Function GetTimeOffset(ByVal strTime As String) As Double
Dim objReg As New Regex("(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?")
Dim objMatch As Match
Dim objLanuch As TimeSpan
Dim objOffsetSpan As TimeSpan
If Not objReg.IsMatch(strTime) Then
Return -1
End If
objMatch = objReg.Match(strTime)
If String.Empty.Equals(objMatch.Groups(3).Value) Then
objLanuch = New TimeSpan(Integer.Parse(objMatch.Groups(1).Value), _
Integer.Parse(objMatch.Groups(2).Value), _
0)
Else
objLanuch = New TimeSpan(Integer.Parse(objMatch.Groups(1).Value), _
Integer.Parse(objMatch.Groups(2).Value), _
Integer.Parse(objMatch.Groups(3).Value))
End If
objOffsetSpan = objLanuch.Subtract(DateTime.Now.TimeOfDay)
If objOffsetSpan.TotalMilliseconds <= 0 Then
objOffsetSpan = objOffsetSpan.Add(New TimeSpan(1, 0, 0, 0))
End If
Return objOffsetSpan.TotalMilliseconds
End Function
Dim objReg As New Regex("(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?")
Dim objMatch As Match
Dim objLanuch As TimeSpan
Dim objOffsetSpan As TimeSpan
If Not objReg.IsMatch(strTime) Then
Return -1
End If
objMatch = objReg.Match(strTime)
If String.Empty.Equals(objMatch.Groups(3).Value) Then
objLanuch = New TimeSpan(Integer.Parse(objMatch.Groups(1).Value), _
Integer.Parse(objMatch.Groups(2).Value), _
0)
Else
objLanuch = New TimeSpan(Integer.Parse(objMatch.Groups(1).Value), _
Integer.Parse(objMatch.Groups(2).Value), _
Integer.Parse(objMatch.Groups(3).Value))
End If
objOffsetSpan = objLanuch.Subtract(DateTime.Now.TimeOfDay)
If objOffsetSpan.TotalMilliseconds <= 0 Then
objOffsetSpan = objOffsetSpan.Add(New TimeSpan(1, 0, 0, 0))
End If
Return objOffsetSpan.TotalMilliseconds
End Function
No comments:
Post a Comment