Convert DateTime to TimeSpan

前端 未结 5 1678
离开以前
离开以前 2020-12-03 12:56

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 on

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 13:41

    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).

    If you simply want to convert a DateTime to a number you can use the Ticks property.

提交回复
热议问题