The purchase receipt from the amazon app store has a purchase date formatted as "Wed Feb 02 17:28:08 GMT+00:00 2022" however I'm not sure how to properly convert this to a valid DateTime due to the timezone offset being included.
DateTime.Parse("Wed Feb 02 17:28:08 GMT+00:00 2022");
The standard DateTime.Parse function just throws FormatException: String was not recognized as a valid DateTime.
How can I parse this string as DateTime?
EDIT:
A commented suggested DateTimeOffset.Parse however this also gives the same FormatException
DateTimeOffset.Parse("Wed Feb 02 17:28:08 GMT+00:00 2022", CultureInfo.InvariantCulture);
You can try
DateTimeOffset.ParseExactwhere you pass the expected format string. The correct format string for your date is"ddd MMM dd HH:mm:ss 'GMT'zzz yyyy":However, you'll still have issues if
GMTdoesn't appear in the string, but some other Timezome string does. You could tryTryParseExactinstead, and if it fails to parse then replace the Timezone characters in the string (assuming there will always be 3 characters GMT, CST, etc):To use
ParseExactorTryParseExactyou need to know the expected format string before parsing.