日期转时间戳
public Int64 ToUnixTimestamp(DateTime date)
{
DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0);
TimeSpan unixTimeSpan = date – unixEpoch;
return (Int64)unixTimeSpan.TotalSeconds-28800;
}
时间戳转日期
public DateTime UnixTimestampToDateTime(Int64 unixTime)
{
DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
long unixTimeStampInTicks = (long)(unixTime * TimeSpan.TicksPerSecond);
return new DateTime(unixStart.Ticks + unixTimeStampInTicks);
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/16421.html