1 标准时间转为时间戳
public static int DateTimeToStamp(DateTime time)
{
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
return (int)(time - startTime).TotalSeconds;
}
2 时间戳转为标准时间
public static DateTime ConvertDateTimeToInt(long time)
{
DateTime Time = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
DateTime dateTime = Time.AddMilliseconds(time * 1000);
return dateTime;
}
评论 (0)