iOS Question DateTime.DateParse problem

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

It might be a dumb question but I can't find an answer.

I have a simple code

DateTime.DateParse:
Try
        DateTime.TimeFormat="HH:mm:ss"
        DateTime.DateFormat="MM/dd/yyyy"
                
        Dim l As Long
    
        l=DateTime.DateParse("11/26/2020 11:52:20")
        xui.MsgboxAsync("L=" & l, "B4X")
        
    Catch
        Log(LastException)
        xui.MsgboxAsync(LastException,"B4X")
    End Try

In B4i it crashes on line 7 (highlighted) with an exception
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 " Error parsing: 11/26/2020 11:52:20" UserInfo={NSLocalizedDescription= Error parsing: 11/26/2020 11:52:20}>

but if I copy / past it into B4A - it works.

What am I doing wrong?

Thanks
 

Star-Dust

Expert
Licensed User
Longtime User
In B4I you don't have to put the time in DateParse. If you need the time you have to use.

DateTimeParse (Date As String, Time As String) As Long

see this: B4i DateTime

In B4A it is indifferent, but it is always better to use the right command
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thank you for a quick replay. I've got an extra headache. Now I need to split a string to separate a date from time.
Divide it with the SPACE char, you can use Regex or IndexOf. It is not difficult. Do the same in B4A so you have code uniformity
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Upvote 0
D

Deleted member 103

Guest
Hi all.

It might be a dumb question but I can't find an answer.

I have a simple code

DateTime.DateParse:
Try
        DateTime.TimeFormat="HH:mm:ss"
        DateTime.DateFormat="MM/dd/yyyy"
               
        Dim l As Long
   
        l=DateTime.DateParse("11/26/2020 11:52:20")
        xui.MsgboxAsync("L=" & l, "B4X")
       
    Catch
        Log(LastException)
        xui.MsgboxAsync(LastException,"B4X")
    End Try

In B4i it crashes on line 7 (highlighted) with an exception
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 " Error parsing: 11/26/2020 11:52:20" UserInfo={NSLocalizedDescription= Error parsing: 11/26/2020 11:52:20}>

but if I copy / past it into B4A - it works.

What am I doing wrong?

Thanks

This is how it should work in B4i.

B4X:
    'DateTime.TimeFormat="HH:mm:ss"
    DateTime.DateFormat="MM/dd/yyyy HH:mm:ss"
                
    Dim l As Long
    
    l=DateTime.DateParse("11/26/2020 11:52:20")
    Log("L=" & l)
    Log("Datum=" & DateTime.Date(l))

Log:
L=1606387940000
Datum=11/26/2020 11:52:20
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
This is how it should work in B4i.

B4X:
    'DateTime.TimeFormat="HH:mm:ss"
    DateTime.DateFormat="MM/dd/yyyy HH:mm:ss"
               
    Dim l As Long
   
    l=DateTime.DateParse("11/26/2020 11:52:20")
    Log("L=" & l)
    Log("Datum=" & DateTime.Date(l))

Log:
L=1606387940000
Datum=11/26/2020 11:52:20
Thanks
 
Upvote 0
Top