Strange error when parsing string to date?

前端 未结 4 2011
清酒与你
清酒与你 2021-01-02 18:07

When I try to parse date like this:

DateTime t1 = DateTime.ParseExact(\"August 11, 2013, 11:00:00 PM\", \"MMMM dd, yyyy, hh:mm:ss tt\", System.Globalization.         


        
4条回答
  •  -上瘾入骨i
    2021-01-02 18:41

    Because your string

    string s = "‎August ‎11, ‎2013, ‏‎11:00:00 PM";
    

    Includes 0x200e(8206) character at the beginning and end of August. You can see it easily by

    var chars = s.ToCharArray();
    

    Seems to be a copy+paste problem

    You can remove those chars by:

    var newstr = new string(s.Where(c => c <128).ToArray())
    

提交回复
热议问题