转换日期时间为时间跨度 [英] Convert DateTime to TimeSpan
问题描述
好日子,大家好, 我想转换一个DateTime实例到一个时间跨度的实例,这可能吗?我环顾四周,但我找不到我想要的,我只觉得时间差。更多specefically,A要转换的DateTime实例为毫秒将其保存在IsolatedStorage
Good Day Guys, I want to convert a DateTime instance into a TimeSpan instance, is it possible? I've looked around but I couldn't find what I want, I only find time difference. More specefically, A want to convert DateTime instance into milliseconds to save it in IsolatedStorage
推荐答案
要转换的DateTime
到时间跨度
你应该选择一个基准日期/时间 - 例如2000年1月1日,并从的DateTime
值减去它(当你想转换回的DateTime $ C $添加午夜C>)。
To convert a DateTime
to a TimeSpan
you should choose a base date/time - e.g. midnight of January 1st, 2000, and subtract it from your DateTime
value (and add it when you want to convert back to DateTime
).
如果你只是想转换一个的DateTime
来了一些可以使用的 蜱
属性。
If you simply want to convert a DateTime
to a number you can use the Ticks
property.
这篇关于转换日期时间为时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!