C # parse datetime "Fri Jan 14, 2011 2:56:36 PM GMT-0800 (Pacific Standard Time)"

I do

 DateTime dt = DateTime.ParseExact(stringDate, "ddd MMM dd yyyy HH:mm:ss UTCzzzzz zzzz", System.Globalization.CultureInfo.InvariantCulture);

But this generates an error (the error was that the date was not in the correct format). Do you know what the correct syntax is?

The date:

Fri Jan 14 2011 15:00:39 GMT-0800 (Pacific Standard Time)

+3
source share
2 answers

This seems to work if you split the end of the line.

var stringDate = "Fri Jan 14 2011 15:00:39 GMT-0800";
var dt = DateTime.ParseExact(
        stringDate,
        "ddd MMM dd yyyy HH:mm:ss 'GMT'zzz",
        System.Globalization.CultureInfo.InvariantCulture);
+4
source

Is Fri Jan 14 2011 15:00:39 GMT-0800 (Pacific Standard Time)that what is in your timeline? If so, your format mask or your input line is incorrect. Please refer to the MSDN library.

This sample is taken from the documentation.

// Parse date and time with custom specifier.
//            Fri Jan 14 2011 15:00:39 GMT-0800
dateString = "Sun 15 Jun 2008 8:30 AM -06:00";
format = "ddd dd MMM yyyy h:mm tt zzz";
try {
   result = DateTime.ParseExact(dateString, format, provider);
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
}
catch (FormatException) {
   Console.WriteLine("{0} is not in the correct format.", dateString);
}

If I were to assume, you are not providing the correct time zone format.

0

Source: https://habr.com/ru/post/1785557/


All Articles