I have been having problems parsing datetimes taken from a MYSQL database.
I have finally tracked down the problem to the Datetime.dateparse function.
Can anyone spot what is wrong here.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Private datestring = "2023-02-10T18:15:22.000000Z"
Try ' I would expect this to succeed
DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm:ss.000000Z"
Private da1 As Long = DateTime.DateParse(datestring)
Log("Parse 1 success")
Catch
Log(LastException)
Log("Date parse 1 failure")
End Try
Try ' I would expect this to fail
DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm:ss"
Private da1 As Long = DateTime.DateParse(datestring)
Log("Parse 2 success")
Catch
Log(LastException)
Log("Date parse 2 failure")
End Try
End Sub
output from log,
Logger connected to: Google Pixel 2 XL
--------- beginning of main
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(ParseException) java.text.ParseException: Unparseable date: "2023-02-10T18:15:22.000000Z"
Date parse 1 failure
Parse 2 success
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Why does the wrong date format parse the date correctly?
The same code runs as expected on iOS.