获取时间戳(毫秒级和秒级)

  /// <summary>
        /// 获取时间戳
        /// </summary>
        /// <param name="bflag">true 秒 , false 毫秒</param>
        /// <returns></returns>
        public static string GetTimeStamp(bool bflag)
        {
            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;
        }

 

posted @ 2022-07-15 19:22  博客YS  阅读(175)  评论(0编辑  收藏  举报