关于DateTime错误

时间:2013-10-28 06:33:49

标签: c#-4.0 datetime

我正在检索日期并传递给函数:

Bind(GetDate(Convert.ToString(Session["TransDate"])),
GetDate((Convert.ToDateTime(Session["TransDate"]).AddDays(1)).ToString("MM-dd-yyyy")));

获取日期功能如下所述:

private String GetDate(String strDate)
{
        String strDate1 = String.Empty;
        if (strDate != "")
        {
            String[] arrDate = strDate.Split('/');
            if (arrDate.Length == 1)
            {
                arrDate = strDate.Split('-');
            }
            strDate1 = arrDate[1] + "/" + arrDate[0] + "/" + arrDate[2];
        }
        return strDate1;
}

它给了我错误:

 "string was not recognized as a valid date time".

1 个答案:

答案 0 :(得分:0)

试试这个

DateTime.Now.ToString("MM dd yy"");

DateTime dt = DateTime.Now; 
string s = dt.ToString("MM dd yy"");

s= "10 28 13";