There is this example code, but then it starts talking about millisecond / nanosecond problems.
The same question is on MSDN, Seconds since the Unix epoch in C#<
You can use DateTimeOffset.
For example. I have DateTime object
var dateTime=new DateTime();
If I want convert the it to Unix time stamps, I can be achieve as follows
var unixTimeSeconds= new DateTimeOffset(dateTime).ToUnixTimeSeconds()
For more information please visit this link : DateTimeOffset.ToUnixTimeSeconds Method