如何获得在C#中unix时间戳 [英] How to get the unix timestamp in C#

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

问题描述

我有计算器左右的样子,甚至看着一些建议的问题,并似乎没有回答,你怎么在C#中的UNIX时间戳?

I have had look around stackoverflow, and even looked at some of the suggested questions and none seem to answer, how do you get a unix timestamp in C#?

推荐答案

您使用DateTime.UtcNow和减去1970-01-01 EPOC的时间拿到C#中的Unix时间戳。

You get a unix timestamp in C# by using DateTime.UtcNow and subtracting the epoc time of 1970-01-01.

例如

Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

DateTime.Now 可以与你想获得Unix时间戳任何的DateTime 对象替换。

DateTime.Now can be replaced with any DateTime object that you would like to get the unix timestamp for.

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

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