1 using System; 2 using System.Collections.Generic; 3 using System.Text; 4 5 namespace TJCFinanceWriteOff.BizLogic.Common 6 { 7 public class UnixTimeUtil 8 { 9 /// <summary> 10 /// 将dateTime格式转换为Unix时间戳 11 /// </summary> 12 /// <param name="time"></param> 13 /// <returns></returns> 14 public static string ConvertDateTimeToUnix(DateTime time) 15 { 16 return ((time.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString(); 17 } 18 19 /// <summary> 20 /// 将Unix时间戳转换为dateTime格式 21 /// </summary> 22 /// <param name="unix"></param> 23 /// <returns></returns> 24 public static DateTime ConvertUnixToDateTime(string unix) 25 { 26 DateTime startUnixTime = System.TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), TimeZoneInfo.Local); 27 return startUnixTime.AddSeconds(double.Parse(unix)); 28 } 29 } 30 }