I copied your code above, and it works fine for me.
B4X:
Sub Button1_Click
Dim pubDate As String' = item.Get("pubDate")
pubDate="Fri, 24 Dec 2021 20:59:36 GMT"
DateTime.DateFormat = "EEE, dd MMM yyyy HH:mm:ss Z"
Dim lDate As Long = DateTime.DateParse(pubDate)
DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss"
Dim sDate As String = DateTime.Date(lDate)
Log(sDate)
End Sub
main_button1_click (java line: 404)
java.text.ParseException: Unparseable date: "Fri, 24 Dec 2021 20:59:36 GMT"
at java.text.DateFormat.parse(DateFormat.java:358)
at anywheresoftware.b4a.keywords.DateTime.DateParse(DateTime.java:148)
at b4a.exampled.main._button1_click(main.java:404)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6161)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
pubDate="Fri, 24 Dec 2021 20:59:36 GMT"
DateTime.DateFormat = "EEE, dd MMM yyyy HH:mm:ss Z" 'lower or upper Z
Dim lDate As Long = DateTime.DateParse(pubDate)
DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss"
Dim sDate As String = DateTime.Date(lDate)
Log(sDate) '12/24/2021 15:59:36
pubDate="Fri, 24 Dec 2021 20:59:36 GMT"
DateTime.DateFormat = "EEE, dd MMM yyyy HH:mm:ss Z" 'lower or upper Z
Dim lDate As Long = DateTime.DateParse(pubDate)
DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss"
Dim sDate As String = DateTime.Date(lDate)
Log(sDate) '12/24/2021 15:59:36
this work
B4X:
Dim jo As JavaObject
jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("US")))
Dim pubDate As String' = item.Get("pubDate")
pubDate="Fri, 24 Dec 2021 20:59:36 GMT"
DateTime.DateFormat = "EEE, dd MMM yyyy HH:mm:ss Z"
Dim lDate As Long = DateTime.DateParse(pubDate)
DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss"
Dim sDate As String = DateTime.Date(lDate)
Log(sDate)
Just to clarify.
The problem is 'Fri' and 'Dec' in the date.
This works only when the device language is set to English.
On my device, the code in post #1 works OK if I replace 'Fri' by 'ven' and 'Dec' by 'déc' because my device language is set to French.
The solution in post #6 was to set the language to English.