Date Formatting C#

前端 未结 7 1358
生来不讨喜
生来不讨喜 2021-01-27 08:32

I am having an issue converting this date format into another format. I was hoping that somebody on here would be able to help me out.

Here is my code:

s         


        
7条回答
  •  无人共我
    2021-01-27 09:34

    string fromFormat = "ffffd, dd MM yyyy HH:mm:ss zzz"; 
    

    The error is your zzz, it is expecting the numerical representation of the timezone, not the abbreviation of the timezone.

    So a acceptable version would be

    DateTime newDate = DateTime.ParseExact("Mon, 22 03 2013 00:00:00 +0:00", fromFormat, null);
    

    but that would throw a different FormatExecption with the message "String was not recognized as a valid DateTime because the day of week was incorrect." If you make the Monday to Friday correction the parse works

    DateTime newDate = DateTime.ParseExact("Fri, 22 03 2013 00:00:00 +0:00", fromFormat, null);
    

    I don't think there is a format specifier that can take in the textual abbreviation version of the timezone.

提交回复
热议问题