I need to find a date format which could adapt to the two following dates:
2012-01-22T14:27:31.176+00002012-01-22T14:27:31+0000
As you can see, the only difference is that date 2 does not have the fractional seconds.
The two date formats would be:
yyyy-MM-dd'T'HH:mm:ss.SZyyyy-MM-dd'T'HH:mm:ssZ
with the second one omitting .S.
Is it possible to make .S optional? Or do I have to keep using 2 different formats?
The problem lies in the fact that I’m getting the date from an API call, and sometimes it comes with the fractional seconds, other times without.
I guess I could detect the presence of the decimal place and use the two different date formats accordingly, but I was looking for a cleaner solution.
Thanks!
The “lenient” property suggested by @JustSid in this case did not work.
Having not found a “cleaner” solution, I went back to my first one, which was detecting the presence of the decimal place and using the two different date formats accordingly.