c# 中Datetime时间格式与Unix时间格式的相互转换
/// <summary>
/// UnixTime-->Datetime
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
private static DateTime ConvertIntDateTime(long unixTime)
{
DateTime time = System.DateTime.MinValue;
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
time = startTime.AddSeconds(unixTime);
return time;
}
/// <summary>
/// Datetime-->UnixTime
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
private static long ConvertDateTimeInt(DateTime time)
{
double intResult = 0;
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
intResult = (time - startTime).TotalSeconds;
return (long)intResult;
}