请高人指点,谢谢!
解决方案 »
- 关于Dispose方法
- 水晶报表问题
- 如何取出gridview中的某行的某个值?
- 使用第三方控件ASPxGridView 出现提示 表 DXMainTable 必须按以下顺序包含行节: 标题、正文和脚注。是什么原因呢
- 跪求ASP.net(C#)写的源代码下载网址!!!!!!!
- DataGrid(Web) 里面的控件
- 谁帮我讲讲postback !
- 关于asp.net中如何控制Response.Write()输出的问题!
- 关于SQL语言的问题
- 请教各位我保存数据到数据表中为什么随机生成id在我新建的表中id值和其他表的id值不一样呢
- 高分求助,如何获取JS代码!
- Request.Form 的求助
string str="2009-09-09";DateTime.TryParse(str,out dt);Console.WriteLine(dt.ToString("yyyy-MM-dd"));
DateTime.TryParse
DateTime.Parse
DateTime.ParseExact
DateTime.Parse(str.ToString("yyyy-MM-dd"));
DateTime.Parse 还是别用这个方法了,改用TryParse吧!DateTime.ParseExact这方法还么用过!
这个方法如果转换失败则抛出异常!而TryParse转换失败的话会返回falseDateTime dt;
string str="2009-09-09";if(DateTime.TryParse(str,out dt))
{
Console.WriteLine(dt.ToString("yyyy-MM-dd"));
}
else
{
Console.WriteLine("转换失败!");
}
DateTime time1 = DateTime.ParseExact(dt,"yyyyMMdd", info1, DateTimeStyles.AllowWhiteSpaces);当然还有Convert.ToDateTime 方法,这个在某些情况也能用吧。
这个方法如果转换失败则抛出异常! 而TryParse转换失败的话会返回false
C# codeDateTime dt;
string str="2009-09-09"; if(DateTime.TryParse(str,out dt))
{
Console.WriteLine(dt.ToString("yyyy-MM-dd"));
}
else
{
Console.WriteLine("转换失败!");
}