分享在C#中时间戳是怎么转换的?

发布时间:2022-05-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了分享在C#中时间戳是怎么转换的?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
时间戳转DateTime

timestamp为10位秒级* 10000000,若为13位毫秒级*10000。

PRivate DateTime TimestampToDateTime(long timestamp)

{

DateTime dateTimeStart = TimeZone.currentTimeZone.ToLocalTime(new DateTime(1970,1,1));

long lTime = timestamp * 10000000;

TimeSpan nowTimeSpan = new TimeSpan(lTime);

DateTime resultDateTime = dateTimeStart.Add(nowTimeSpan);

return resultDateTime;

}

DateTime转时间戳

秒级

private int DateTimeToTimestamp(DateTime time)
{
DateTime startDateTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(197, 1, 1));
return Convert.ToInt32((time - startDateTime).totalSeconds);

}

以上就是分享在C#中时间戳是怎么转换的?的详细内容,更多请关注脚本宝典其它相关文章

脚本宝典总结

以上是脚本宝典为你收集整理的分享在C#中时间戳是怎么转换的?全部内容,希望文章能够帮你解决分享在C#中时间戳是怎么转换的?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。