Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find how many seconds past since 1/1/1970

Tags:

c++

I am looking for a function in C++ that calculates how many seconds have past from 1/1/1970 until today.

like image 415
yonatan Avatar asked Nov 16 '10 16:11

yonatan


People also ask

How do you calculate time since 1970?

POSIX defines that you can deduce the number of days since The Epoch (1970-01-01 00:00:00Z) by dividing the timestamp by 86400. This deliberately and consciously ignores leap seconds.

Why is the epoch January 1 1970?

January 1st, 1970 at 00:00:00 UTC is referred to as the Unix epoch. Early Unix engineers picked that date arbitrarily because they needed to set a uniform date for the start of time, and New Year's Day, 1970, seemed most convenient.

What is the time since 1970 called?

The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).

How do you calculate seconds from dates?

Multiply the two dates' absolute difference by 86400 to get the Epoch Time in seconds – using the example dates above, is 319080600.


1 Answers

#include <time.h>

time_t seconds_past_epoch = time(0);

Available on most operating systems.

like image 125
aschepler Avatar answered Oct 10 '22 08:10

aschepler