Unparseable date with parseDateTime

0
Hello,   I'm trying to convert a string into a date. But parseDateTime isn't working. I always get the error "Unparseable date". This is my string: 2/8/2024 6:28:56 AM This is my format: M/d/yyyy h:mm:ss a When I run "parseDateTime('2/8/2024 6:28:56 AM','M/d/yyyy h:mm:ss a')" I get the error "Unparseable date".   Now I tried some tests. I used a typical american date format: String: 02/08/2024 6:28:56 AM Format: MM/dd/yyyy h:mm:ss a Here I also get the same error.   BUT! when I remove the "AM" or "PM" from the date and the "a" from the format it is working! String: 02/08/2024 6:28:56 Format: MM/dd/yyyy h:mm:ss parseDateTime('2/8/2024 6:28:56','M/d/yyyy h:mm:ss') This is working without problems.   I also created a JAVA Action. Now the funny part starts :D When I only run the Java with the exact same string localy in Eclipse, it is working fine. But wenn I add the same Java function into my Java Action in Mendix, I get the same Error: Unparseable date   Is this a setting error?   Best regards
asked
3 answers
1

Do you have English set as the language in your application?

 

You may be using a different locale that doesn't know about AM or PM. When I swap my language over to Dutch parsing the date fails, but works in English.

 

I think this is what is happening in this case.

answered
0

I think you need to double up some of those characters as they aren't always single characters. The following works for me.

 

parseDateTime('2/8/2024 6:28:56 AM','MM/dd/yyyy hh:mm:ss aa')

 

I hope this helps!

answered
0

im having similair issue.

my error:

10:09:04 PM
Unparseable date: "10:09:04 PM"
Failed to evaluate expression, error occurred on line 1, character 1
parseDateTime($Time, 'HH:mm:ss aa')

 

 

it works fine with AM, but the PM trips up the parser

answered