How do I get the unix timestamp in C as an int?

Tim picture Tim · Aug 1, 2012 · Viewed 193.8k times · Source

I would like to get the current timestamp and print it out using fprintf.

Answer

Dmitry Poroh picture Dmitry Poroh · Aug 1, 2012

For 32-bit systems:

fprintf(stdout, "%u\n", (unsigned)time(NULL)); 

For 64-bit systems:

fprintf(stdout, "%lu\n", (unsigned long)time(NULL));