从数字转换为日期 [英] Convert from number to date
问题描述
我有一个尝试以XML格式解析的现有系统,并试图将其导入SQL.我对日期的特定字段有疑问.我希望有人可以看一下并弄清楚这些数字的含义,因为我尝试了很多不同的事情,但无法弄清楚.
I have an existing system that is in XML Format that I am trying to parse and import into SQL. I''m having an issue with a particular field for dates. I was hoping someone could look at this and figure out what these numbers mean, because I have tried a lot of different things and can''t figure it out.
<modifiedDate>1105323339</modifiedDate>
<createdDate>1097507448</createdDate>
<startDate>1097507448</startDate>
<date>1105323339</date>
我能想到的最好的方法是一定的时间跨度,但不是很确定.看来它们都有相似的数字,但是我不知道如何将其转换为任何形式的VB.NET Date.我已经尝试过
The best I can come up with is that it''s some sort of timespan, but not really sure. It does appear that they all have a similar number, but I can''t figure out how to convert this to a VB.NET Date of any kind. I''ve tried
Dim tspan As New TimeSpan(Convert.ToInt32(cNode.InnerText))
Dim createdDate As New Date(tspan.Ticks)
但这还不足以根据它创建日期,它最终只是一个时间.
But it''s not big enough to create a date out of it and it ends up just being a time.
推荐答案
基本上,假设输入时给出从公历0001年1月1日00:00:00.000开始计算的正确的100-ns滴答数,可以使用以下构造函数构造System.DateTime
的实例:
http://msdn.microsoft.com/en-us/library/z2xf7zzk.aspx [ ^ ].
如果这是另外一回事,则您需要知道它是什么,然后显然可以通过适当的缩放和移动来获取正确的刻度数.这很容易.
—SA
Basically, assuming that on input you are given the correct number of 100-ns tick counted from January 1, 0001 at 00:00:00.000 in the Gregorian calendar, you can construct the instance ofSystem.DateTime
using this constructor:
http://msdn.microsoft.com/en-us/library/z2xf7zzk.aspx[^].
If this is something else, you need to know what it is, and then obtain correct number of ticks, apparently by appropriate scaling and shifting. This is easy.
—SA
这篇关于从数字转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!