码迷,mamicode.com
首页 > Windows程序 > 详细

C# 时间与时间戳互转 13位

时间:2018-12-03 20:23:11      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:timezone   tst   tick   rtt   localtime   param   new t   start   sum   

/// <summary>
/// 将c# DateTime时间格式转换为Unix时间戳格式
/// </summary>
/// <param name="time">时间</param>
/// <returns>long</returns>
public static long ConvertDateTimeToInt(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
long t = (time.Ticks - startTime.Ticks) / 10000; //除10000调整为13位
return t;
}
/// <summary>
/// 时间戳转为C#格式时间
/// </summary>
/// <param name=”timeStamp”></param>
/// <returns></returns>
private DateTime ConvertStringToDateTime(string timeStamp)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}

C# 时间与时间戳互转 13位

标签:timezone   tst   tick   rtt   localtime   param   new t   start   sum   

原文地址:https://www.cnblogs.com/KyrieCC/p/10060022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!