13位时间戳转换成标准时间C#代码

时间:2021-04-04 02:35:55

 

 1     /// <summary>
 2     /// 时间戳转换成标准时间
 3     /// </summary>
 4     /// <param name="timeStamp">时间戳</param>
 5     /// <returns></returns>
 6     private DateTime ConvertToTime(string timeStamp)
 7     {
 8         DateTime time = DateTime.Now;
 9         if (string.IsNullOrEmpty(timeStamp))
10         {
11             return time;
12         }
13         try
14         {
15             DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
16             long lTime = long.Parse(timeStamp + "0000");
17             TimeSpan toNow = new TimeSpan(lTime);
18             time = dtStart.Add(toNow);
19         }
20         catch (Exception ex)
21         {
22             log.Warn(ex.Message);
23 } 24 return time; 25 }