How to get timestamp in C#

Record the method of C# to get the timestamp

method one


 public long GetTimeStamp()
  {
    
    
      TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
      return Convert.ToInt64(ts.TotalSeconds);
  }

Method Two

 public static long GetTimeStamp()
  {
    
    
       TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
       return Convert.ToInt64(ts.TotalSeconds);
  }

method three

 public static long GetTimeStamp()
  {
    
    
		return new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
  }

Guess you like

Origin blog.csdn.net/qq_41841073/article/details/127788934