Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get epoch time in C#? [duplicate]

Tags:

c#

datetime

epoch

People also ask

What is time_t type in C?

The time_t datatype is a data type in the ISO C library defined for storing system time values. Such values are returned from the standard time() library function. This type is a typedef defined in the standard <time.

What type of value is returned by the time () function?

Returns the decimal number for a particular time. If the cell format was General before the function was entered, the result is formatted as a date. The decimal number returned by TIME is a value ranging from 0 (zero) to 0.99988426, representing the times from 0:00:00 (12:00:00 AM) to 23:59:59 (11:59:59 P.M.).

What does time 0 do in C?

We can declare a variable to hold the current time from the system using: time_t now = time(0); time(0) can also be use in generating random values: #define SEED time(0); srand((unsigned int )SEED);


TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
int secondsSinceEpoch = (int)t.TotalSeconds;
Console.WriteLine(secondsSinceEpoch);