iOS Question Is there a equivalent for "ParseTime" in the iOS?

Discussion in 'iOS Questions' started by niveasoft, Jun 14, 2018.

  1. niveasoft

    niveasoft Member Licensed User

    Hello
    I want to sort time from 6 in the morning to the 22 on the night as valid time.
    Everything dont match should return false.
    In the Android this was a piece of cake:
    Code:
    Sub check_night_silent_conditions()As Boolean
           
        
    Dim under As Long
        
    Dim above As Long
        
    Dim timenow As Long
        
    DateTime.TimeFormat = "HH:mm:ss"
        under = 
    DateTime.TimeParse("06:00:00")
        above = 
    DateTime.TimeParse("23:59:59")
       
        timenow = 
    DateTime.now
       
        
    If under < timenow Then 'below 6 in the morning
            hd.ToastMessageShow("Sterownik nie zezwoli","CISZA NOCNA!")
            
    Return False
        
    Else
            
    If above > timenow Then 'above 22 of the night
                hd.ToastMessageShow("Sterownik nie zezwoli","CISZA NOCNA!")
                
    Return False
            
    End If
        
    End If
       
        
    Return True
    End Sub
    Is there a equivalent for iOS like in the post theme mentioned?

    Thanks in advance and sorry if I search awkwardly :D
     
  2. Cableguy

    Cableguy Expert Licensed User

    Those should be part of the core lib in b4i
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    It was a mistake to add TimeParse to B4J and B4A. It was not added to B4i. Parsing a time string without a clear date is problematic in some cases.

    You should instead use DateTime.DateTimeParse. In all platforms.
     
    Cableguy likes this.
  4. niveasoft

    niveasoft Member Licensed User

    Okay. This is tested and it work fine.
    Code:
    Sub check_night_silent_conditions()As Boolean
               
        
    DateTime.TimeFormat = "HH:mm:ss"
        
    Dim timenow As Long = DateTime.Now
        
    Dim datenow As String = DateTime.Date(timenow)
        
    Dim under As Long = DateTime.DateTimeParse(datenow,"06:00:00")
        
    Dim above As Long = DateTime.DateTimeParse(datenow,"21:59:59")

        
    If timenow < under Then
        
    Return False
        
    Else If timenow > above Then
        
    Return False
        
    End If
      
    Return True 
    End Sub
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Small tip:
    Code:
    If timenow < under Then
        
    Return False
        
    Else If timenow > above Then
        
    Return False
        
    End If
      
    Return True
    Equivalent to:
    Code:
    Return timenow >= under AND timenow <= above
     
    Cableguy likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice