UNIX时间戳转DateTime类型

摘要 : UNIX timestamp turn DateTime type

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);
}
#endregion

/// <summary>
/// 将c# DateTime时间格式转换为Unix时间戳格式
/// </summary>
/// <param name="time">时间</param>
/// <returns>double</returns>
public int ConvertDateTimeInt(System.DateTime time)
{
 int intResult = 0;
 System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
 intResult = (int)(time - startTime).TotalSeconds;
 return intResult;
}
上一篇 :C#如何获取CPU使用率
下一篇 :C#发送多附件邮件