C# 时间戳与DateTime间的互相转换

//DateTime转换为时间戳
public
long GetTimeSpan(DateTime time) { DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1,0,0,0,0));
    return (long)(time - startTime).TotalSeconds; }
//timeSpan转换为DateTime
public DateTime TimeSpanToDateTime(long span)
{
  DateTime time = DateTime.MinValue;
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1,0,0,0,0));
  time=startTime.AddSeconds(span);
  return time;
}

 

posted @ 2016-09-22 16:20  被遗忘者灬  阅读(8272)  评论(0编辑  收藏  举报