Android Question Unparseable date

Pendrush

Well-Known Member
Licensed User
Longtime User
I'm getting this error on some devices
B4X:
java.text.ParseException: Unparseable date: "Sun, 05 Feb 2017 22:06:02 +0100" (at offset 0)
with this code
B4X:
DateTime.DateFormat = "EEE, dd MMM yyyy HH:mm:ss Z"
Dim sDate As String = "Sun, 05 Feb 2017 22:06:02 +0100"
Dim lngDate As Long = DateTime.DateParse(sDate) '<- Error in this line

I'm unable to reproduce it on my devices, but I can see errors on live (store) application.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your code will fail on devices with non-English locales.

Add this code to Service_Create of the starter service:
B4X:
Dim jo As JavaObject
jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("US")))
This will set the default locale to be US (of the process only) and the dates will be parsed correctly.
 
Upvote 0
Top