B4J Question Unparseable Date Error with B4J Ver 8.9

Elby dev

Member
Licensed User
After upgrading to B4J Ver 8.9 My program crashes with java.text.ParseException: Unparseable date: "22-FEB-2021". Yet when I run the same code under Ver 8.5 it is fine.
Interestingly when I change the month text to ie February it works. Unfortunately my incoming dates are like 22-Feb-2021 etc.
Is this a bug or am I missing something? Thanks. Hope someone can shed some light. Below the code I used for testing.
B4X:
Private Sub Button1_Click
    DateTime.DateFormat = "dd-MMM-yyyy"
    Log(DateTime.DateParse("22-FEB-2021"))
    'Log result with B4J  8.5  =  1613912400000
    'Run with B4J 8.9 throws an Error
    'java.text.ParseException: Unparseable date: "22-FEB-2021"
End Sub
 

klaus

Expert
Licensed User
Longtime User
I get an error too.
But, in my case the problem is the language, my computer language is set to french.
I looked to see what I get with : Log(DateTime.Date(DateTime.Now)) > 17-févr.-2021
This: Log(DateTime.DateParse("22-FEB-2021")) throghs an error
This: Log(DateTime.DateParse("22-févr.-2021")) works, with this value: 1613948400000

The difference in the tick values is due to the time zones.
 
Upvote 0

Elby dev

Member
Licensed User
Thanks Agraham for the reply. I changed the path from Java JDK 11 to Java 8 (191) and now it does work in B4J V8.9. Get the value
1613912400000 for 22-Feb-2021. Something Screwy with my Java 11. Which I like as it allows me to create stand alone pkg.
I'll get a new download of Java 11 and try again. At least I am getting somewhere.
 
Upvote 0

Elby dev

Member
Licensed User
I get an error too.
But, in my case the problem is the language, my computer language is set to french.
I looked to see what I get with : Log(DateTime.Date(DateTime.Now)) > 17-févr.-2021
This: Log(DateTime.DateParse("22-FEB-2021")) throghs an error
This: Log(DateTime.DateParse("22-févr.-2021")) works, with this value: 1613948400000
Also Thank you. With my Current B4J v8.9 and JDK 11.0.1 (from b4j website)
My :Log(DateTime.DateParse("22-FEB-2021")) throws an error but is ok with java 8
My :Log(DateTime.DateParse("22-FEBRUARY-2021")) is OK with both Java 8 and 11.
I'll reinstall everything as I have not done ever, always just updated.
Will let you know. Thanks
 
Upvote 0

Elby dev

Member
Licensed User
Hi All, Have reinstalled B4j 8.9 and JDK 11.0.1 but the error is still there.
So for now I have changed my incoming date ie 22-FEB-2021 to 22-FEBRUARY-2021 for all 12 months
using the substring and substring2 commands before converting to ticks. This works fine, just a bit more code
and I can still build a standalone. If there is a will then there is a way to do it. ;)
I will try some other V11 JDK as the issue is with Java and report here.
Thanks all for the tips so far.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
No problems here (JDK 11 from B4X.com)

B4X:
DateTime.DateFormat = "dd-MMM-yyyy"
Log(DateTime.DateParse("22-FEB-2021"))
Log(DateTime.Date(1613948400000))


B4X:
Waiting for debugger to connect...
Program started.
1613948400000
21-Feb.-2021
 
Upvote 0

Elby dev

Member
Licensed User
Sorry for the late reply. Lots of work here down under.
Thank You Erel you are spot on !! Adding the "java.util.Locale" lines fixed the problem.
The Dateparsing now works with both FEB or FEBRUARY.
I now suspect an earlier Microsoft Windows update. As the error was occurring on 3 pc's.
ps Having the Locale set to English US or English Australia the error will occur with Java jdk 11 but not with Java 8.
To be sure I will be adding your suggested line to my programs when using Dateparsing and 3 Character month names.
Thank You for the solution.
Reg Elbert
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I would have thought that using such format would be considered as a bad coding habit...
only in very specific situations have I seem dates formated that way, and in every case of them, a more "standart" format like (dd-mm-yyyy) was accepted.
 
Upvote 0

Elby dev

Member
Licensed User
Thanks Cableguy. I think this is going a bit off topic. Bad coding or not FEB or 02 or FEBRUARY are all allowed formats when looking at options within Java and Excell.
If this is 'bad' then java and excell people would not have this included as allowables.
I don't like it either but this is the output from a large commercial enterprise Pronto so I have to work with FEB as an input field. That is why I am stuck with it.
I like 2 digit month numbers. Better still I like Erel's 'ticks for dates even better as it is much easier to work with.
Ps I am still looking for a wall calendar with month's displayed as '02' ?
In the end it all comes to a person or peoples 'choice' of thing's within the rules.... i suppose. Thank's anyway.
 
Upvote 0
Top