In my ASP.Net app, I am receiving a date string from PayPal and when I try to convert it to UTC date it always fails. I have tried this conversion in LINQPad tool but I always get that the date string could not be successfully parsed.
The date string that my ASP.Net page receives from PayPal is like this: 08:45:29 May 25, 2016 PDT
Question: How can I successfully convert the PayPal received date to UTC date in C#? The code that I have tried so far is given below.
Code in LINQPad for conversion of PayPal date to UTC date
string payPalDateString = "08:45:29 May 25, 2016 PDT";
DateTime date = DateTime.Now;
if( DateTime.TryParse(payPalDateString, out date) == true) {
"payPalDateString was successfully parsed".Dump();
DateTime dateUTC = date.ToUniversalTime();
dateUTC.Dump("payPalDateString in UTC is as below");
} else {
payPalDateString.Dump("payPalDateString was NOT successfully parsed");
}
PayPal documentation says the following about the date it sends.
Time/Date stamp generated by PayPal, in the following format: HH:MM:SS DD Mmm YY, YYYY PST
The above date format mentioned in PayPal documentation should actually have been: HH:mm:ss MMM dd, yyyy PST