如何将双值转换为C#中的日期时间? [英] How to convert a double value to a DateTime in c#?
问题描述
我有值40880.051388和我把它作为一个双,如果我打开Excel和在细胞浆,并应用以下自定义格式 M / D / YYYY H:MM
该单元格,我得到2011/12/3 1:14
I have the value 40880.051388 and am storing it as a double, if I open Excel and paste in a cell and apply the following custom format "m/d/yyyy h:mm"
to that cell, I get "12/3/2011 1:14"
如何我在C#这解析/转换?我不知道,如果该值是毫秒从某个校验点,象信号出现时间,或如果该值是在一些特定的准备的格式,但如何的excel拿出这个特定值?可以在C#做什么?
How can I do this parsing/Conversion in C#? I don't know if the value is milliseconds from a certain checkpoint, like epoch time, or if the value is in some specific prepared format, but how does excel come up with this particular value? Can it be done in C#?
我试着时间跨度工作
,的DateTime
,以及其他类似Visual Studio中的东西,但我没有在任何地方得到。
I've tried working with TimeSpan
, DateTime
, and other like things in Visual Studio but am not getting anywhere.
推荐答案
看起来你重新使用旧 OLE自动化日期。使用
Looks like you're using the old OLE Automation date. Use
DateTime.FromOADate(myDouble)
这篇关于如何将双值转换为C#中的日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!