There are other posts on this subject but they all seem closed without an answer.
Is there a function to easily convert an ISO DateTime string to a Pega DateTime? Many answers that I've seen posted say to use the FormatDateTime function. While that can be used to format a Pega DateTime to the ISO format, it does not work if you provide an ISO formatted date as input.
Here's an example of formatting a Pega DateTime as ISO:
Thanks for the code for this function. I wanted to make sure there wasn't something already out of the box before I created my own.
If you look closely at your test result, there's a bug in your code. The input you tested with, 2020-06-10T20:38:36.700Z, has 'Z' for the time zone which means UTC (or GMT). And we want the output to also be UTC / GMT, but the hour value in your result is different from the input. In your code it seems that the date is being converted as if the input was in your local time zone rather than UTC / GMT.
I updated your code to fix this bug and also to use only one datetime library rather than 2 different ones.
After looking at this some more, I decided to use java.time instead of org.joda.time. I've also created a function that uses "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" as the default pattern but can take other patterns as a parameter.
That's great Michael. We have a better solution now which will help many. My code was not done/tested as part of any application I worked. I just tried and did a basic testing after I saw this question yesterday and found that there was no solutions in other posts.
After posting this I found an OOTB function called pxConvertISODateTimeToPegaInternalFormat. It takes a Page as input instead of a single string value. I haven't tested it yet and the documentation is not clear to me. I'm wondering if it finds and converts every value that looks like an ISO formatted date in the page? If so, that could be useful.
Michael, I can confirm that this is the case. It's will convert any ISO Date and Date Time format on the given page into the Pega internal Date and DateTime format. What it doesn't convert is a TimeOfDay format, ie time format only.
In that case, seems like it's a good option to convert dates coming back in response payloads for REST connectors all in one shot. It would be nice to have detailed documentation on how it works and exactly what format is expected. I've seen very small format differences (like weather or not there's a colon in the timezone offset) cause problems for date time parsing code. Since this operates on a Page, it's more complex to "unit test" and ensure it's going to work for the format we are dealing with.