c# - 特殊日期时间格式为字符串,看起来像 double

标签 c# datetime format

我必须为外部应用程序创建一个 xml 文件我没有文件结构的描述,所以我必须通过逆向工程来创建它。原始所需文件具有属性

LastChange = "43061.2997590394"

我认为这是特殊日期时间格式的结果。

DateTime.Parse("43061.2997590394") 抛出异常。

有人知道这是什么格式吗?

最佳答案

使用DateTime.FromOADate

double oaValue = double.Parse("43061.2997590394", CultureInfo.InvariantCulture);
DateTime dt = DateTime.FromOADate( oaValue );  // Result: 11/22/2017 07:11:39

来自 MSDN 的评论:

An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25.

The base OLE Automation Date is midnight, 30 December 1899. The minimum OLE Automation date is midnight, 1 January 0100. The maximum OLE Automation Date is the same as DateTime.MaxValue, the last moment of 31 December 9999.

关于c# - 特殊日期时间格式为字符串,看起来像 double,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47830513/

相关文章:

c# - 由 MS Excel 和 COM 托管的 C#2 中的委托(delegate)中的异常行为

c# - VB6 到 COM 可调用包装的 .NET - 查找 .NET 库的问题

linux - 如何使用 QML 更改系统日期和时间(嵌入式 Linux)?

c# - CultureInfo 根据计算机设置更改

c# - Async/Await 如何处理 "old"结果?

来自 Facebook API 的 PHP 日期转换

c# - 准时双排版

erlang - 为什么erlang io是:format output being lost and what do I need to do to restore it?

Java getTimeInstance(DateFormat.SHORT)针对不同的语言环境输出不同的格式?

c# - 如何设置一次性电子邮件别名(craigslist 样式)?