开发者

.NET Timespan object: How do I get the Start and End DateTime?

Consider this:

Dim StartDate As DateTime = #06/12/2010 6:32PM#
Dim EndDate As DateTime = #06/13/2010 10:47PM#
Dim ElapsedSpan As TimeSpan = StartDate - EndDate

Does the TimeSpan ob开发者_如何转开发ject retain the original Start and End datetimes that make up the span period? It doesn't appear to and only seems to store the amount of time elapsed not the actual end points.

If I want this too, should I create my own class, I suppose or is there a better object?


No, TimeSpan is a single measurement of an amount of time, not a specific start and end time.


That is correct, timespan does not store anything dealing with the original dates as you used them above. The only reason you get a timespan with that is that the - operator is overloaded for datetime to return a timespan. I don't know of any class that would do this for you.


Have a look at the DateTimeOffset structure. This does almost what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜