C# Tips

C# Tip Article

How to get unix timestamp in C#

The unix time stamp is the number of seconds between a particular date and the Unix Epoch(1970/1/1) at UTC. In C#, this timestamp can be obtained by simple time calculation as below:

// get unix timestamp
int timestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
//

Technically unix timestamp will stop working on 2038/1/19 because of 32bit overflow.