1、时间戳转日期
public static DateTime IntToDateTime(int timestamp){
return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1)).AddSeconds(timestamp);
}
调用:IntToDateTime(1458637638);
输出:2016/3/22 17:7:18
2、日期转时间戳
public static DateTime DateTimeToInt(DateTime datetime){
return (datetime.ToUniversalTime().Ticks - new DateTime(1970, 1, 1).Ticks) / 10000000
}
调用: DateTimeToInt(DateTime.Now);
输出:1458638060