New to using Time library trying to serial print current hour

I am very new to the Arduino programming language and have some sporadic experience with other languages, but overall pretty new to all this.

I am trying to learn how to use the Time library. I have downloaded and imported and included the library. I have successfully used other non standard libraries as well so far.

I am simply trying to Serial.print the current hour (or minute or time etc..). I have reviewed forums and searched google for answers. I have looked at the sketchbook examples and can't figure out what I'm doing wrong. It seems soooo simple to do what I want to do. Its probably so simple that there aren't any examples to be found ::slight_smile:

Here's my code:

#include "Time.h"
#include "TimeLib.h"

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

void loop()
{
  time_t t = now();
  Serial.print(hour());
  delay(5000);
}

When I verify this code its fine, and then I upload it to my board. Then when I open the serial monitor, I am expecting to see the current hour but instead I see "0". Again I want to see the current hour. I just can't figure out what I'm doing wrong here.

I really appreciate your time and help.

I really appreciate your time and help.

I am expecting to see the current hour but instead I see "0"

You're not setting the current time.

As in:
setTime(hr,min,sec,day,month,yr); // do this in setup()

.

Thank you so much, it works perfectly now. I didn't understand the set up I guess, it makes sense now. Thank you again.