是否.NET框架的支持,让基于UNIX时间戳当前时间以秒为单位? [英] Does the .NET framework support getting the current time in seconds based on UNIX timestamp?

查看:138
本文介绍了是否.NET框架的支持,让基于UNIX时间戳当前时间以秒为单位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果.NET包含了一个方法,当前时间,以秒或毫秒转换为UNIX时间戳(1970/1/1从偏移量)?

解决方案

 时间跨度T =(DateTime.UtcNow  - 新的日期时间(1970年,1,1));
Console.WriteLine((INT)t.TotalSeconds);
 

I am wondering if .NET contains a method to convert the current time in seconds or milliseconds to a UNIX timestamp (offset from 1970/1/1)?

解决方案

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

这篇关于是否.NET框架的支持,让基于UNIX时间戳当前时间以秒为单位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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