/// <summary> /// 时间戳转为C#格式时间 /// </summary> /// <param name=”timeStamp”></param> /// <returns></returns> static public 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); }
/// <summary> /// DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name=”time”></param> /// <returns></returns> static public int ConvertDateTimeInt(System.DateTime time) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); return (int)(time - startTime).TotalSeconds; }
本文介绍如何将时间戳转换为C#格式时间,并提供了一个实用的转换方法,便于开发者在C#项目中灵活使用时间数据。
173

被折叠的 条评论
为什么被折叠?



