C# .NET equivalent to PHP time()
(int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds
It's not clear why you need an equivalent for PHP time()
, but you can do:
var secondsSinceUnixEpoch = DateTime.UtcNow
.Subtract(new DateTime(1970, 1, 1))
.TotalSeconds;
// If needed.
var roundedSeconds = (int) secondsSinceUnixEpoch;