转载:http://www.u3d8.com/?p=1112
/// <summary>
/// 生成时间戳
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
private long ConvertDateTimeToLong(DateTime time) //System.DateTime.Now
{
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
//TotalSeconds 生成十位的时间戳 ;TotalMilliseconds生成十三位的时间戳
return (long)(time - startTime).TotalSeconds; //
}
/// <summary>
/// 解析时间戳
/// </summary>
/// <param name="timeStamp"></param>
/// <returns></returns>
private DateTime ConvertLongToDateTime(long timeStamp)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1,0,0,0));
long lTime = long.Parse(timeStamp + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}
网友评论