mkTime() returning time from last year

I’m trying to reassemble the time_t variables year(),month(),day(),hour(),minute(),second() back into serialized format.

I’ve set it up like this:

//NTP stuff  https://www.pjrc.com/teensy/td_libs_Time.html & https://github.com/PaulStoffregen/Time
#include <Time.h>
#include <TimeLib.h>

char timeServer[] = "ntp.sdyoung.com";
WiFiUDP Udp;
unsigned int ntpPort = 8888;
int timeZone = -7;

void setup() {
Udp.begin(ntpPort);
  Serial.println(F("Waiting for NTP sync"));
  setSyncProvider(getNtpTime);

time_t s_tm = tmConvert_t(year(),month(),day(),hour(),minute(),second()); 
Debug.println(s_tm);
}

time_t tmConvert_t(int YYYY, byte MM, byte DD, byte hh, byte mm, byte ss) { 
  tmElements_t tm;
  tm.Year = YYYY;
  tm.Month = MM;
  tm.Day = DD;
  tm.Hour = hh;
  tm.Minute = mm;
  tm.Second = ss;
  return makeTime(tm); 
}

const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets

time_t getNtpTime() {
  while (Udp.parsePacket() > 0) ; // discard any previously received packets
  Serial.println(F(" <--- Transmit NTP Request"));
  sendNTPpacket(timeServer);
  uint32_t beginWait = millis();
  while (millis() - beginWait < 1500) {
    int size = Udp.parsePacket();
    if (size >= NTP_PACKET_SIZE) {
      Serial.println(F(" ---> Received NTP Response"));
      Udp.read(packetBuffer, NTP_PACKET_SIZE);  // read packet into the buffer
      unsigned long secsSince1900;
      // convert four bytes starting at location 40 to a long integer
      secsSince1900 =  (unsigned long)packetBuffer[40] << 24;
      secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
      secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
      secsSince1900 |= (unsigned long)packetBuffer[43];
      return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
    }
  }
  Serial.println(F(" ---> No NTP Response :-("));
  return 0; // return 0 if unable to get the time
}

// send an NTP request to the time server at the given address
//void sendNTPpacket(IPAddress &address) {
void sendNTPpacket(char* address) {
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;
  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:                 
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer, NTP_PACKET_SIZE);
  Udp.endPacket();
} 

void loop() {

}

The result of s_tm is not the current timestamp. But if I print the variables individually then they are correct. Why would the timestamp from the function return a different value?

Output:

(d) -1473112402
(d) 2017Year
(d) 7Month
(d) 10Day
(d) 15Hour
(d) 3Mins
(d) 12Secs

The var s_tm returns Monday, September 5, 2016 9:53:22 PM or Saturday, April 28, 1923 2:06:38 AM depending if I omit the negative indicator preceding the value. As I reload the sketch the serialized value is decrementing toward zero. Any thoughts?

Figured it out.

Wrong:

tm.Year = YYYY;

Right:

tm.Year = YYYY - 1970;

Why do you need two Time libraries?

A more expressive way is:

tm.Year = CalendarYrToTm(YYYY)