来自UNIX时代的日期时间格式 [英] Datetime format from UNIX epoch
本文介绍了来自UNIX时代的日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用这段代码来获取给定的UNIX时代的格式datetime
I use this code to get the format datetime of a given UNIX epoch
DateTime epoch=new DateTime(1970,1,1);
DateTime dt=new DateTime(1325506582751000+epoch.Ticks());
输出结果为1975 / x / y
The output result is 1975/x/y
这是不正确的。
是否定义了时代?如何从任何给定的日期时间数据中获得正确的数据?
Is the epoch incorrectly defined ? How can I get the correct one from any given datetime data ?
推荐答案
尝试这个
public DateTime FromUnixTime(long unixTime)
{
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return epoch.AddSeconds(unixTime);
}
或者你可以阅读这个文章。
这篇关于来自UNIX时代的日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文