C# 获取当前时间戳

 /// <summary>
        /// 获取当前时间戳,10位,秒
        /// </summary>
        /// <returns></returns>
        public string GetTimeStamp()
        {
            TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt64(ts.TotalSeconds).ToString();
        }

        /// <summary>
        /// 获取时间戳,13位,毫秒
        /// </summary>
        /// <returns></returns>
        public static string GetTimeStamps()
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt64(ts.TotalMilliseconds).ToString();
        }   

 

posted @ 2020-05-18 10:01  学竹  阅读(4998)  评论(0编辑  收藏  举报