user35434: I am building a time-critical system using Arduino. Is there any way to get the elapsed seconds like time.h of C in Arduino? I tried time(NULL) but it returns 0. Then moved forward to use now() in Time.h. But the result persists. 
How can I get the elapsed seconds since Jan 1, 1970 until now?

user29650: The accepted answer is not the only (nor best) answer. It depends what you have in hand.
The Time library will allow your arduino to keep the current time, it just need to be set the time periodically (because of clock shifting issues)
There are several ways you can get the current time:

Use a GPS module
Get time from NTP server if you have network access to one, using an Ethernet shield or may be wifi
Use a custom Serial interface
Use a GSM service 
Use a RTC module, may be the most popular and standalone, like the DS3231. However these kind of module will also require some adjustment in the long term, and they require a backup battery (often a coin like CR2032) to keep time when module is not externally powered.
Use a few push buttons and LCD to have the user manually input it.
Use a light sensor to see when it is the brightest time of the day and using azimuth calculation determine the hour of the day (ok, I might be going to far here, but consider a solar powered device in the middle of nowhere)

I sorted them in the order I would choose it if I have several options available.
Those are a few ways that come to my mind

user38174: You must use an RTC module like DS3231 or DS1307 for such purposes and there are good libraries available for these modules;
Unlike the standard return value of milli seconds elapsed since Jan 1 1970 00:00 on a computer, the millis() function on arduino just returns the number of milliseconds since the board began running the current program and this number will overflow (go back to zero), after approximately 50 days as per the official documentation at https://www.arduino.cc/en/Reference/Millis
While millis() can be used for very basic time controlled operations, its not really reliable to be used for time critical operations;

user359: An arduino does not have a real time clock (RTC) built in. Every time it restarts it will reset the millis counter.
You will need to add a RTC peripheral that you can poll to find the current date and time.

35434: <p>I am building a time-critical system using Arduino. Is there any way to get the <strong>elapsed seconds</strong> like <code>time.h</code> of <strong>C</strong> in Arduino? I tried <code>time(NULL)</code> but it returns <code>0</code>. Then moved forward to use <code>now()</code> in <code>Time.h</code>. But the result persists. </p>

<p>How can I get the elapsed seconds since Jan 1, 1970 until now?</p>
 29650: <p>The accepted answer is not the only (nor best) answer. It depends what you have in hand.
The <a href="https://playground.arduino.cc/Code/Time" rel="nofollow noreferrer">Time library</a> will allow your arduino to keep the current time, it just need to be set the time periodically (because of clock shifting issues)
There are several ways you can get the current time:</p>

<ul>
<li>Use a GPS module</li>
<li>Get time from NTP server if you have network access to one, using an Ethernet shield or may be wifi</li>
<li>Use a custom Serial interface</li>
<li>Use a GSM service </li>
<li>Use a RTC module, may be the most popular and standalone, like the DS3231. However these kind of module will also require some adjustment in the long term, and they require a backup battery (often a coin like CR2032) to keep time when module is not externally powered.</li>
<li>Use a few push buttons and LCD to have the user manually input it.</li>
<li>Use a light sensor to see when it is the brightest time of the day and using azimuth calculation determine the hour of the day (ok, I might be going to far here, but consider a solar powered device in the middle of nowhere)</li>
</ul>

<p>I sorted them in the order I would choose it if I have several options available.
Those are a few ways that come to my mind</p>
 38174: <p>You must use an RTC module like DS3231 or DS1307 for such purposes and there are good libraries available for these modules;</p>

<p>Unlike the standard return value of milli seconds elapsed since Jan 1 1970 00:00 on a computer, <strong>the millis() function on arduino just returns the number of milliseconds since the board began running the current program</strong> and this number will overflow (go back to zero), after approximately 50 days as per the official documentation at <a href="https://www.arduino.cc/en/Reference/Millis" rel="nofollow noreferrer">https://www.arduino.cc/en/Reference/Millis</a></p>

<p>While millis() can be used for very basic time controlled operations, its not really reliable to be used for time critical operations;</p>
 359: <p>An arduino does not have a real time clock (RTC) built in. Every time it restarts it will reset the millis counter.</p>

<p>You will need to add a RTC peripheral that you can poll to find the current date and time.</p>
