C#取时间戳

public DateTime GetTime(string timeStamp) 

         { 

             DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); 

             long lTime = long.Parse(timeStamp + "0000000"); 

             TimeSpan toNow = new TimeSpan(lTime); 

             return dtStart.Add(toNow); 

         } 

  

         // DateTime时间格式转换为Unix时间戳格式 

         public int ConvertDateTimeInt(System.DateTime time) 

         { 

             System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); 

             return (int)(time - startTime).TotalSeconds; 

         }

posted @ 2010-08-17 12:03  itecho  阅读(758)  评论(0编辑  收藏  举报