您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 雅安分类信息网,免费分类信息发布

如何在 C# 中获取 Unix 时间戳

2024/3/7 0:06:14发布27次查看
unix时间戳主要用于unix操作系统。但对大家都有帮助操作系统,因为它代表所有时区的时间。
unix 时间戳代表以秒为单位的时间。 unix 纪元从 1 日开始1970 年 1 月。
因此,unix 时间戳是特定日期之间的秒数
示例使用 datetime.now.subtract 获取 unix 时间戳( ).总秒数方法
class program{ static void main(string[] args){ int32 unixtimestamp = (int32)(datetime.now.subtract(new datetime(1970, 1, 1))).totalseconds; console.writeline("the unix timestamp is {0}", unixtimestamp); console.readline(); }}
输出1596837896
exampleto get the unix timestamp using datetimeoffset.now.tounixtimeseconds() 方法
class program{ static void main(string[] args){ var unixtimestamp = datetimeoffset.now.tounixtimeseconds(); console.writeline("the unix timestamp is {0}.", unixtimestamp); console.readline(); }}
输出1596819230.
示例使用 timespan 结构体方法获取 unix 时间戳
class program{ static void main(string[] args){ timespan epochticks = new timespan(new datetime(1970, 1, 1).ticks); timespan unixticks = new timespan(datetime.now.ticks) - epochticks; int32 unixtimestamp = (int32)unixticks.totalseconds; console.writeline("the unix timestamp is {0}.", unixtimestamp); console.readline(); }}
输出1596839083
以上就是如何在 c# 中获取 unix 时间戳的详细内容。
雅安分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录