I have time span in OLE automation double
units. I would like to convert it into seconds or TimeSpan
object. I searched for related functions in TimeSpan
or DateTime
classes, but couldn't find any.
CodePudding user response:
If you have a OLE Automation date for the start and end-dates you should be able to convert it to a timespan by just calling DateTime.FromOADate and taking the difference between the two values.
If you only have one value it sounds like someone is misusing the data type to represent a timespan instead of a date. I'm not familiar with OLE Automation, but the documentation states:
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.
So I would assume that you should just be able to call TimeSpan.FromDays(...) to produce a timespan.
Once you have a timespan you can just use the TotalSeconds
property if you want seconds.