为什么这给了我错误的输出

为什么这给了我错误的输出

问题描述:

DateTime date = DateTime.Now;
            string str="";
            date =Convert.ToDateTime(dtl.Rows[0]["createddate"].ToString());
            str = date.ToString("mm/dd/yyyy");


            DateTime datenow = DateTime.Now;
            string strnow="";
            strnow = datenow.ToString("mm/dd/yyyy");
            if (str != strnow)
            {

            }



//这两个字符串变量给我一个错误的月份,为什么呢?



//this gives me wrong month for both string variable why? and what is solution for that?

在日期的字符串转换中,小写的mm返回分钟.几个月以来,您必须使用大写字母MM.因此,您的格式字符串应为"MM/dd/yyyy".

也会发生在我身上.
In the string conversion of a date, lower case mm returns the minutes. For months, you must use upper case, MM. Your format string should therefore be "MM/dd/yyyy".

Happens to me, too.