将DateTime转换为长时间,也可以相反 [英] Convert DateTime to long and also the other way around

查看:162
本文介绍了将DateTime转换为长时间,也可以相反的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将日期作为数字存储在表中。我知道如何做,但我不知道怎么回去。如何为ToDateTime投一个长变量。

I want to store dates as numbers in a table. I know how to do that but I don't know how to go back. How can I cast a long variable to ToDateTime.

DateTime now = DateTime.Now;
long t = now.ToFileTime();
DateTime today = t.ToDateTime;  // I am looking for something like this line. This Method does not exist

我知道有很多方法可以将DateTime转换为很长时间。我不介意使用哪种技术。我只想有一种可以来回转换的方法。

I know there are many ways of converting DateTime to long. I don't mind which technique to use. I just want to have a way where I can convert back and forth.

推荐答案

从DateTime开始:

To long from DateTime:

long DateTime.Ticks

从长的日期时间:

new DateTime(long)

这篇关于将DateTime转换为长时间,也可以相反的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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