Giter Club home page Giter Club logo

Comments (4)

blackketter avatar blackketter commented on August 26, 2024

The tmElements_t data structure you are creating is not valid.

Keep in mind that the years in a tmElements structure are since 1970 and that the months start at 1 (for January) as do the days.

I hope this helps.

from time.

BenShen98 avatar BenShen98 commented on August 26, 2024

Thanks for your help.
But I don't think this would be a problem as the time_t means how many seconds has passed after 1/1/1970.
Also, When I change the day to 1, month to 1, year to 1970, it returns 1322155904 which is 17:31:44 11-24-2011, it just totally doesn't make sense.

from time.

BenShen98 avatar BenShen98 commented on August 26, 2024

Would you mind try this or similar code on your Arduino? As it's possible because something wrong with my IDE on the computer. But it didn't help even after I reinstalled this Time library.

from time.

PaulStoffregen avatar PaulStoffregen commented on August 26, 2024

Indeed your error is use of 0 for tm.Day and tm.Month.

I just tested this code:

#include <Time.h>
void setup() {
  Serial.begin(9600);
}

void loop() {
  setTime(sync());
  Serial.print(now());
  Serial.print(" ");
  Serial.print(hour());
  Serial.print(':');
  Serial.print(minute());
  Serial.print(':');
  Serial.print(second());
  Serial.print(' ');
  Serial.print(month());
  Serial.print('-');
  Serial.print(day());
  Serial.print('-');
  Serial.println(year());
  delay(500);
}
time_t sync() {
  tmElements_t tm;
  tm.Hour = 0;
  tm.Minute = 0;
  tm.Second = 0;
  tm.Day = 1;
  tm.Month = 1;
  tm.Year = 0;
  return makeTime(tm);
}

This is the result in the serial monitor:

0 0:0:0 0-0-1970
0 0:0:0 0-0-1970
0 0:0:0 0-0-1970
0 0:0:0 0-0-1970
0 0:0:0 0-0-1970

Time is working properly. You simply used 0 in those fields which begin at 1.

from time.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.