Hi, I found this library yesterday( Arduino Playground - Time )
I think it is pretty useful, because I need to get what is the current hour, minute of the day.
I followed all the instructions on how to install it and I required it with:
#include <TimeLib.h> #include <Time.h>
But when I upload it to my arduino and when I use serial.println( now() ) or serial.println( year() ), I get 0 for now() and 1970 for year()
AWOL:
You didn't set the time in the code you didn't post?
What do you mean, set the time?
Do you mean this?
time_t t = now(); // Store the current time in time
hour(t); // Returns the hour for the given time t
minute(t); // Returns the minute for the given time t
pupolajshu:
Okay, now it shows correct time.
Is there a way to get current Unix Timestamp in code (Without RTC)?
You can keep time any way you want, but it won't be easy or accurate without an RTC.
Your code has no way to magically know what the current time is. It has to be input into memory somewhere and continually kept track of. RTCs are built for this exact application, and are designed with a battery backup to keep them ticking when power is removed. You're Arduino won't have that, and would need the time reset every time the power is cycled.