adb shell date
returned the string : Wed May 18 19:18:08 IST 2022
I am able to parse this string using
DateTime currentdateTime = DateTime.ParseExact(deviceCurrentDateTime, "ddd MMM dd HH:mm:ss 'IST' yyyy", CultureInfo.InvariantCulture);
But when adb shell date returned the string : Thu May 5 19:18:01 IST 2022 (two spaces after May)
then above parseExact is not working.
How to use multiple formats to parse the two dates?
You can do something like this where you replace your double space with a single space. Usually you'd expect to see a 0 rather than a space in most cases, but hey ho.
Note I've also replaced your format string with "ddd MMM d HH:mm:ss 'IST' yyyy"
EDIT:
Example where it's working
Prints: 05/05/2022 19:18:01
Prints: 18/05/2022 19:18:01