1、当前时间转换为时间戳:
public static int ConvertDatetimeToInt(System.DateTime now) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970,1,1)); return (int)(now - startTime).TotalSeconds;}
2、时间戳转换为当前时间:
public DateTime getDatetime(String timeStamp){ System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); long lTime = long.Parse(timeStamp + "0000000"); TimeSpan toNow = new TimeSpan(lTime); return startTime.Add(toNow); }