C#朱利安日期解析器 [英] C# Julian Date Parser
本文介绍了C#朱利安日期解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在电子表格中有一个单元格,它是Excel中的一个日期对象,但是当它从C1的xls类中出来时变成了双精度(类似于1/7/2009的39820.0).我读到这是儒略日期格式.有人可以告诉我如何将其解析回C#中的DateTime吗?
I have a cell in a spreadsheet that is a date object in Excel but becomes a double (something like 39820.0 for 1/7/2009) when it comes out of C1's xls class. I read this is a Julian date format. Can someone tell me how to parse it back into a DateTime in C#?
更新:看来我可能没有儒略日期,而是自1899年12月30日以来的天数.
Update: It looks like I might not have a Julian date, but instead the number of days since Dec 30, 1899.
推荐答案
I think Excel is just using the standard OLE Automation DATE type which can be converted with the DateTime.FromOADate
method.
这段代码,
using System;
namespace DateFromDouble
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(DateTime.FromOADate(39820.0));
}
}
}
输出:
1/7/2009 12:00:00 AM
这篇关于C#朱利安日期解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文