C#时间戳与日期互转
///
/// 时间戳转为C#格式时间
///
/// Unix时间戳格式
/// C#格式时间
public static DateTime GetTime(string timeStamp)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}
///
/// DateTime时间格式转换为Unix时间戳格式
///
/// DateTime时间格式
/// Unix时间戳格式
public static int ConvertDateTimeInt(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
return (int)(time - startTime).TotalSeconds;
}
使用C#把发表的时间改为几个月,几天前,几小时前,几分钟前,或几秒前
///
/// 使用C#把发表的时间改为几个月,几天前,几小时前,几分钟前,或几秒前
///
/// </