Cloud Training (Online)




How to get the Unix Timestamp in C# ?

You can get the Unix timestamp in C# by subtracting the epoch time of 1st January 1970 from current UTC time.

How to get the Unix Timestamp in C# ?

Here’s a sample code snippet demonstrating how to get the unix timestamp in .NET.

using System;
public class Hello {
    public static void Main() {
        int unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)))
        .TotalSeconds;
        System.Console.WriteLine(unixTimestamp);
    }
}

Output