转换日期时间为时间跨度 [英] Convert DateTime to TimeSpan

查看:136
本文介绍了转换日期时间为时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好日子,大家好, 我想转换一个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 )。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆