概述
时间戳转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#中时间戳是怎么转换的?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复