如何在 C# 中获得纪元时间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9453101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 07:28:37  来源:igfitidea点击:

How do I get epoch time in C#?

c#datetimeepoch

提问by James Jeffery

Possible Duplicate:
How do you convert epoch time in C#?

可能的重复:
如何在 C# 中转换纪元时间?

I'm trying to figure out how to get the epoch time in C#. Similar to the timestamps given on this website: http://www.epochconverter.com/

我试图弄清楚如何在 C# 中获得纪元时间。类似于本网站上给出的时间戳:http: //www.epochconverter.com/

Does DateTime have a method for that?

DateTime 有这样的方法吗?

回答by Darin Dimitrov

TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
int secondsSinceEpoch = (int)t.TotalSeconds;
Console.WriteLine(secondsSinceEpoch);