为什么这给了我错误的输出 [英] why this is giving me wrong output
本文介绍了为什么这给了我错误的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 casemm
returns the minutes. For months, you must use upper case,MM
. Your format string should therefore be"MM/dd/yyyy"
.
Happens to me, too.
这篇关于为什么这给了我错误的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文