C# 时间戳

        /// <summary>
        /// 时间戳
        /// </summary>
        /// <returns></returns>
        public static string Time()
        {
            //DateTime dateTime = DateTime.Now;
            //var start = new DateTime(1970, 1, 1, 0, 0, 0);
            //decimal SecondsTime = Convert.ToDecimal((dateTime - start).TotalSeconds);
            //return decimal.Round(SecondsTime, 3).ToString().Replace(".", "");
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
            long timeStamp = (long)(DateTime.Now - startTime).TotalMilliseconds; // 相差毫秒数
            return timeStamp.ToString();
        }

  

猜你喜欢

转载自www.cnblogs.com/hblc/p/12306705.html