How to get the current date and time in seconds (since Jan 1, 1970 - Unix time 0) using C#

1 Answer

0 votes
using System;
  
class CurrentTimeInSecondsUnixTime0_CSharp
{
    static void Main() {
        long milliseconds = DateTimeOffset.Now.ToUnixTimeMilliseconds();
        
        long seconds = milliseconds / 1000;
        
        Console.WriteLine(seconds);
    }
}
  
  
  
/*
run:
  
1723189112
 
*/

 



answered Aug 9, 2024 by avibootz
...