The time library's now() function returns 0 and year() returns 1970

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()

What could be the problem?

#include <TimeLib.h>
#include <Time.h>

void setup() {
  Serial.begin(9600);
}

void loop() {

  Serial.println(now());
  Serial.println(year());
  delay(1500);
}

What could be the problem?

You didn't set the time in the code you didn't post?

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

Try here

AWOL:
Try here

wow, tremendous help...

pupolajshu:
What do you mean, set the time?

the time is initially set to 0 (zero) which is Jan, 1, 1970 in UNIX time.

you need to set the time using one of the methods in the examples that came with the IDE's Time Library.

what example code are you using?

BulldogLowell:
wow, tremendous help...

I know.
It's great, isn't it, that someone took the time and effort to create and register that website?

AWOL:
I know.
It's great, isn't it, that someone took the time and effort to create and register that website?

... the power of sarcasm

BulldogLowell:
wow, tremendous help...

the time is initially set to 0 (zero) which is Jan, 1, 1970 in UNIX time.

you need to set the time using one of the methods in the examples that came with the IDE's Time Library.

what example code are you using?

I edited the post and added my full code.

Could this be the function?
setTime(t);

pupolajshu:
I edited the post and added my full code.

Could this be the function?
setTime(t);

yes, try putting the command in setup() with a current Unix Timestamp and see...

setTime(1498131869UL); // enters the current time as an integer literal (unsigned long)

BulldogLowell:
yes, try putting the command in setup() with a current Unix Timestamp and see...

setTime(1498131869UL); // enters the current time as an integer literal (unsigned long)

Okay, now it shows correct time.
Is there a way to get current Unix Timestamp in code (Without RTC)?

Have to do it...

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.