如何在C#中获得时代时间? [英] How do I get epoch time in C#?

查看:87
本文介绍了如何在C#中获得时代时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何转换C#中的时代?

我试图找出如何在C#中获取时代。与本网站上提供的时间戳类似: http://www.epochconverter.com/

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/

DateTime是否有一个方法?

Does DateTime have a method for that?

推荐答案

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

这篇关于如何在C#中获得时代时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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