What is the best way to parse a datetime from a string like Tue Sep 12 22:18:36 CEST 2017

0
What is the best way to parse a datetime from a string like " Tue Sep 12 22:18:36 CEST 2017" I have tried parseDateTime($CurrentValue,'yyyy-MM-dd''T''HH:mm:ss') but to no avail...  
asked
4 answers
2

Hi Theo, 

parseDateTime($CurrentValue,'yyyy-MM-dd''T''HH:mm:ss') only works when 'yyyy-MM-dd''T''HH:mm:ss is the correct format. You now assume the date is formatted with  '-'   and looks like 2017-Sep-12 etc. 

It should be more like parseDateTime($CurrentValue,'EEE MM hh:mm:ss yyyy')

You can check how you have to write your format in the links below:

https://docs.mendix.com/refguide/parse-and-format-date-function-calls

https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

 

 

answered
0
parseDateTime($CurrentValue,'EEE MMM hh:mm:ss z yyyy')

This might work.

answered
0

Your input contains redundant data, and I can imagine Java's SimpleDateFormat not wanting to have anything to do with a format that contains redundant data. What works for me is:

parseDateTime( substring($input, find($input, ' ')+1), 'MMM dd hh:mm:ss z yyyy')

This is supposed to strip out the " Tue " part from your input, the remaining String should parse fine.

Maybe the +1 in my line needs to be a +2, not completely sure there.

Edit: As Edwin rightly pointed out, my solution is wrong, it just works for this specific case where Sep is Sep in both Dutch and English but will fail for a date in May.

 

answered
0

If running app in  English language, format 'EEE MMM d HH:mm:ss z yyyy' should parse fine.

If running in another language like Dutch, 'Tue' is not recognized. Date formatted in Dutch with the same format will be something like 'di sep 12 22:18:36 GMT+02:00 2017

Using a Java action, you could specify the locale to be used when parsing a date.

answered