獲取時間戳的方法
/// <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));
很簡單,但是還是寫下來吧,說不定以后能用上
