VS 2017和DateTime.ParseExact错误 [英] VS 2017 and DateTime.ParseExact error

查看:126
本文介绍了VS 2017和DateTime.ParseExact错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。


我安装了新的VS2017,并且在开始使用旧的Web项目后,我遇到了DateTime.ParseExact函数的问题。无论日期字符串是如何格式化的,我都会收到错误"字符串未被识别为有效的日期时间"。 。


例如:


//也试过"2017-01-01"

string strDATE =" 01.01.2017" ;;

DateTime dt1 = DateTime.ParseExact(strDATE," dd / MM / yyyy",CultureInfo.InvariantCulture);


这一切都发生在安装VS 2017之后。我也使用了不同的方法(Convert.DateTime ...),但都有相同的错误信息。


来自社区的任何想法?


谢谢。


Marko

解决方案

试试这个:

 string strDATE =" 01.01.2017" ;; 
DateTime dt1 = DateTime.ParseExact(strDATE," dd'。'MM'。'yyyy",CultureInfo.InvariantCulture);


Hello.

I installed new VS2017 and after starting  to work with old web project I faced problems with DateTime.ParseExact function. Irrespective how is the date string formatted I get error "String was not recognized as a valid DateTime" .

For example:

// Also tried "2017-01-01"
string strDATE = "01.01.2017";
DateTime dt1 = DateTime.ParseExact(strDATE, "dd/MM/yyyy", CultureInfo.InvariantCulture);

And all this happened after VS 2017 was installed. I have also used different approaches (Convert.DateTime...), but all have the same error message.

Any thoughts from community?

Thank you.

Marko

解决方案

Try this:

string strDATE = "01.01.2017";
DateTime dt1 = DateTime.ParseExact(strDATE, "dd'.'MM'.'yyyy", CultureInfo.InvariantCulture);


这篇关于VS 2017和DateTime.ParseExact错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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