获取时间戳的方法 

       /// <summary>
        /// 获取时间戳
        /// </summary>
        /// <param name="nowTime">当前时间</param>
        /// <returns>时间戳(type:long)</returns>
        static long GetUnixTime(DateTime nowTime)
        {
            DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0,0));
            return (long)Math.Round((nowTime-startTime).TotalMilliseconds,MidpointRounding.AwayFromZero);
        }

 

把获取到的时间戳转换成byte数组:

byte [] timestamp = System.Text.Encoding.Default.GetBytes(GetUnixTime(DateTime.Now));

很简单,但是还是写下来吧,说不定以后能用上

 

相关文章:

  • 2022-02-04
  • 2022-03-10
  • 2021-06-19
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2023-02-06
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案