无法将类型'string'隐式转换为'System.DateTime' [英] Cannot implicitly convert type 'string' to 'System.DateTime'

查看:549
本文介绍了无法将类型'string'隐式转换为'System.DateTime'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从字符串转换为DataTime,但是发生错误。
我正在使用VS 2003,.NET Framework 1.1

I am trying to convert from string to DataTime but an an error occurs. I am using VS 2003, .NET Framework 1.1

DateTime dt = Convert.ToDateTime("11/23/2010");
string s2 = dt.ToString("dd-MM-yyyy");
DateTime dtnew = Convert.ToString(s2);




无法将类型'string'隐式转换为'System.DateTime'

Cannot implicitly convert type 'string' to 'System.DateTime'

有人可以用语法帮助我吗?

Can any one help me me with the syntax how to solve the error.

推荐答案

string input = "21-12-2010"; // dd-MM-yyyy    
DateTime d;
if (DateTime.TryParseExact(input, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out d))
{
    // use d
}

这篇关于无法将类型'string'隐式转换为'System.DateTime'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆