Strange error when parsing string to date?

前端 未结 4 2010
清酒与你
清酒与你 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:45

    Your second string has hidden characters.

    Run this:

    string s1 = "August 11, 2013, 11:00:00 PM";
    string s2 = "‎August ‎11, ‎2013, ‏‎11:00:00 PM";
    
    Console.WriteLine(s1.Length); // 28
    Console.WriteLine(s2.Length); // 33
    

    Specifically, as char arrays, the second one is this:

    s2.ToCharArray();
    {char[33]}
    [0]: 8206 '‎' // ????
    [1]: 65 'A'
    [2]: 117 'u'
    [3]: 103 'g'
    [4]: 117 'u'
    [5]: 115 's'
    [6]: 116 't'
    [7]: 32 ' '
    [8]: 8206 '‎' // ????
    [9]: 49 '1'
    [10]: 49 '1'
    [11]: 44 ','
    [12]: 32 ' '
    [13]: 8206 '‎' // ????
    [14]: 50 '2'
    [15]: 48 '0'
    [16]: 49 '1'
    [17]: 51 '3'
    [18]: 44 ','
    [19]: 32 ' '
    [20]: 8207 '‏' // ????
    [21]: 8206 '‎' // ????
    [22]: 49 '1'
    [23]: 49 '1'
    [24]: 58 ':'
    [25]: 48 '0'
    [26]: 48 '0'
    [27]: 58 ':'
    [28]: 48 '0'
    [29]: 48 '0'
    [30]: 32 ' '
    [31]: 80 'P'
    [32]: 77 'M'
    

提交回复
热议问题