时间转时间戳 时间戳转时间
/// <summary> /// 时间转 时间戳 /// </summary> /// <param name="time"></param> /// <returns></returns> public string DateToUnix10(DateTime time) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区 long timeStamp = (long)(time - startTime).TotalSeconds; // 相差秒数 return timeStamp.ToString(); } /// <summary> /// 时间戳 转时间 /// </summary> /// <param name="unixTimeStamp"></param> /// <returns></returns> public DateTime Unix10ToDate(long unixTimeStamp) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区 DateTime dt = startTime.AddSeconds(unixTimeStamp); return dt; }
版权声明:本文为qc-id-01原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。