Diferencia entre revisiones de «tmElements t»

De ArduWiki
Saltar a: navegación, buscar
(Comentarios)
(Ejemplo 2)
Línea 56: Línea 56:
  
 
== Ejemplo 2 ==
 
== Ejemplo 2 ==
En este ejemplo usamos la función [[makeTime()]] para crear el Tiempo Unix de una fecha-hora. Ejemplo 2019-3-21 8:00:00
+
En este ejemplo usamos la función [[breakTime()]] para descomponer el Tiempo Unix de una fecha-hora.
  
 
<syntaxhighlight lang="c++">
 
<syntaxhighlight lang="c++">
Línea 62: Línea 62:
 
void setup(){
 
void setup(){
 
   Serial.begin(115200);
 
   Serial.begin(115200);
   tmElements_t tx;
+
  time_t tiempo = 1553155200;
   tx.Second = 0;
+
   tmElements_t tm;
   tx.Minute = 0;
+
  breakTime(tiempo, tm);
   tx.Hour = 8;
+
   Serial.print(tm.Year + 1970);
   tx.Day = 21;
+
  Serial.print("-");
   tx.Month = 3;
+
   Serial.print(tm.Month);
   tx.Year = 49;   //2019-1970
+
   Serial.print("-");
   time_t tiempo = makeTime(tx);
+
   Serial.print(tm.Day);
   Serial.println(tiempo);   //1553155200
+
  Serial.print(" ");
 +
  Serial.print(tm.Hour);
 +
   Serial.print(":");
 +
   Serial.print(tm.Minute);
 +
   Serial.print(":");
 +
   Serial.print(tm.Second);
 
}
 
}
 
void loop(){
 
void loop(){

Revisión del 16:57 27 abr 2019

tmElements_t es una matriz de seis (6) elementos que proporciona la libreria TimeLib.h y que permite manipular de manera facil (sin tener que usar el Tiempo Unix) todos los elementos necesarios para definir una fecha-hora.

Sintaxis

tmElements_t variable;

Parámetros

variable
Nombre de la variable que definiras.

Métodos

Metodos disponibles para tmElementos_t
Metodo Descripcion
.Second Segundo (0~59)
.Minute Minuto (0~59)
.Hour Hora (0~23)
.Day Dia (1~31)
.Month Mes (1~12)
.Year Año (0~99) resta de 1970.

Comentarios

Para representar el año 2019 debes poner 49 (2019-1970) y no olvidar sumar 1920 nuevamente al resultado.

Advertencias

Ejemplo 1

En este ejemplo usamos la función makeTime() para crear el Tiempo Unix de una fecha-hora. Ejemplo 2019-3-21 8:00:00

#include <TimeLib.h>
void setup(){
   Serial.begin(115200);
   tmElements_t tx;
   tx.Second = 0;
   tx.Minute = 0;
   tx.Hour = 8;
   tx.Day = 21;
   tx.Month = 3;
   tx.Year = 49;   //2019-1970
   time_t tiempo = makeTime(tx);
   Serial.println(tiempo);   //1553155200
}
void loop(){
   //Nada
}

Ejemplo 2

En este ejemplo usamos la función breakTime() para descomponer el Tiempo Unix de una fecha-hora.

#include <TimeLib.h>
void setup(){
   Serial.begin(115200);
   time_t tiempo = 1553155200;
   tmElements_t tm;
   breakTime(tiempo, tm);
   Serial.print(tm.Year + 1970);
   Serial.print("-");
   Serial.print(tm.Month);
   Serial.print("-");
   Serial.print(tm.Day);
   Serial.print(" ");
   Serial.print(tm.Hour);
   Serial.print(":");
   Serial.print(tm.Minute);
   Serial.print(":");
   Serial.print(tm.Second);
}
void loop(){
   //Nada
}

Vea también

Referecias