分享在C#中时间戳是怎么转换的?
导读:收集整理的这篇文章主要介绍了分享在C#中时间戳是怎么转换的?,觉得挺不错的,现在分享给大家,也给大家做个参考。时间戳转DateTimetimestamp为10位秒级* 10000000,若为13位毫秒级*10000。PRivate Date...
收集整理的这篇文章主要介绍了分享在C#中时间戳是怎么转换的?,觉得挺不错的,现在分享给大家,也给大家做个参考。时间戳转DateTimetimestamp为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#中时间戳是怎么转换的?的详细内容,更多请关注其它相关文章!
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 分享在C#中时间戳是怎么转换的?
本文地址: https://pptw.com/jishu/592154.html