简体   繁体   English

“对象”不包含“ ToDateTime”的定义

[英]'object' does not contain a definition for 'ToDateTime'

I am writing a script which takes data from fields. 我正在编写一个脚本,该脚本从字段中获取数据。 And I want to convert them to DateTime . 我想将它们转换为DateTime here is the code: 这是代码:

Document.Field("Document Section 1\\Verification Date").Value.ParseExact();

and

Document.Field("Document Section 1\\Verification Date").Value.ParseExact();

I have tried ParseExact , ToDateTime , TryParse , and every time the error is the same. 我已经尝试过ParseExactToDateTimeTryParse ,并且每次错误都是一样的。

'object' does not contain a definition for 'ParseExact' “对象”不包含“ ParseExact”的定义

I am not a C# rockstar, so I will be grateful if you show me right way, not only theritacally, but with code. 我不是C#摇滚明星,因此,如果您以正确的方式,不仅在理论上而且在代码方面向我展示正确的方法,我将不胜感激。

I don't know what the Value is but 我不知道什么是价值,但是

Document.Field("Document Section 1\\Verification Date").Value

will return a object . 将返回一个object

What you need is a String. 您需要的是一个字符串。 This string can then be parsed to DateTime 然后可以将此字符串解析为DateTime
So a solution would be 所以解决方案是

DateTime.Parse(((String)Document.Field("Document Section 1\\Verification Date").Value)

Sidenote: Doesn't DateTime.Parse accept object too? 旁注: DateTime.Parse也不接受object吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM