0

尝试将字符串解析为日期时间时出现错误。我试过这个:

string x = "31/5/2012";   
DateTime d = DateTime.ParseExact(x, "dd'/'MM'/'yyyy", new CultureInfo("en-US"));

string x = "31/5/2012";
DateTime d = DateTime.ParseExact(x, "dd/MM/yyyy", new CultureInfo("en-US"));

string x = "31/5/2012";  
DateTime d = DateTime.ParseExact(x, "dd/MM/yyyy", cultureinfo.invariantculture));

但我仍然遇到同样的错误。

我需要做什么?

4

2 回答 2

3
DateTime d = DateTime.ParseExact(x, "dd/M/yyyy", new CultureInfo("en-US"));

5由于您的字符串日期没有月份05,请使用 singleM

于 2012-06-19T12:59:20.070 回答
0
        string x = "31/5/2012";

        DateTime d = DateTime.ParseExact(x, "dd/M/yyyy", new CultureInfo("en-US"));
于 2012-06-19T13:00:30.097 回答