本文介绍了ASP.NET:获取毫秒,因为1/1/1970的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASP.NET,VB.NET日期,而我试图让毫秒数自1月1日,1970年我试图寻找在MSDN的方法,但我无法找到任何东西。有谁知道如何做到这一点?
I have an ASP.NET, VB.NET Date, and I'm trying to get the number of milliseconds since January 1st, 1970. I tried looking for a method in MSDN, but I couldn't find anything. Does anyone know how to do this?
推荐答案
您可以减去任何两个的DateTime
实例,并获得时间跨度
和 TotalMilliseconds
会给你总毫秒。 。下面的示例
You can subtract any two DateTime
instances and get TimeSpan
and TotalMilliseconds
would give you total milliseconds. Sample below.
DateTime dt1970 = new DateTime(1970, 1, 1);
DateTime current = DateTime.Now;
TimeSpan span = current - dt1970;
Console.WriteLine(span.TotalMilliseconds.ToString());
单行
//DateTime.MinValue is 01/01/01 00:00 so add 1969 years. to get 1/1/1970
DateTime.Now.Subtract(DateTime.MinValue.AddYears(1969)).TotalMilliseconds;
这篇关于ASP.NET:获取毫秒,因为1/1/1970的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!