Android Question Unparseable date

Discussion in 'Android Questions' started by Pendrush, Feb 6, 2017.

  1. Pendrush

    Pendrush Well-Known Member Licensed User

    I'm getting this error on some devices
    Code:
    java.text.ParseException: Unparseable date: "Sun, 05 Feb 2017 22:06:02 +0100" (at offset 0)
    with this code
    Code:
    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.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Your code will fail on devices with non-English locales.

    Add this code to Service_Create of the starter service:
    Code:
    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.
     
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