/// <summary> /// 时间戳转为C#格式时间 /// </summary> /// <param name=”timeStamp”></param> /// <param name="bflag">为真时获取10位时间戳,为假时获取13位时间戳.</param> /// <returns></returns> private DateTime GetTime(string timeStamp, bool bflag = true) { DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime; if (bflag==true) { lTime = long.Parse(timeStamp + "0000000"); } else{ lTime = long.Parse(timeStamp + "0000"); } TimeSpan toNow = new TimeSpan(lTime); return dtStart.Add(toNow); }
/// <summary> /// 获取当前时间戳 /// </summary> /// <param name="bflag">为真时获取10位时间戳,为假时获取13位时间戳.</param> /// <returns></returns> public static string GetTimeStamp(bool bflag = true) { TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); string ret = string.Empty; if (bflag) ret = Convert.ToInt64(ts.TotalSeconds).ToString(); else ret = Convert.ToInt64(ts.TotalMilliseconds).ToString(); return ret; }
时间: 2024-10-10 06:32:38