.net 时间戳和日期互转 【转】http://www.cnblogs.com/zhuiyi/p/5307540.html

.net 时间戳和日期互转

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

原文地址:https://www.cnblogs.com/mmbbflyer/p/5522364.html