Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int diferencia_entre_fechas(std::string fecha1, std::string fecha2)
- {
- //Retorna en segundos la diferencia entre dos fechas dadas
- tm fecha_menor, fecha_mayor;
- time_t epoca1, epoca2;
- strptime(fecha1.c_str(), "%Y-%m-%d %H:%M:%S", &fecha_menor);
- strptime(fecha2.c_str(), "%Y-%m-%d %H:%M:%S", &fecha_mayor);
- //Esto hace lo mismo que las 2 lineas de arriba
- //std::istringstream fmenor(fecha1);
- //std::istringstream fmayor(fecha2);
- //fmenor >> std::get_time(&fecha_menor, "%Y-%m-%d %H:%M:%S");
- //fmayor >> std::get_time(&fecha_mayor, "%Y-%m-%d %H:%M:%S");
- epoca1 = mktime(&fecha_menor);
- epoca2 = mktime(&fecha_mayor);
- //std::cout << fecha_menor.tm_mday << "-" << fecha_menor.tm_mon << "-" << fecha_menor.tm_year << " " <<fecha_menor.tm_hour << ":" << fecha_menor.tm_min << ":" << fecha_menor.tm_sec << "n";
- //std::cout << fecha_mayor.tm_mday << "-" << fecha_mayor.tm_mon << "-" << fecha_mayor.tm_year << " " <<fecha_mayor.tm_hour << ":" << fecha_mayor.tm_min << ":" << fecha_mayor.tm_sec << "n";
- //std::cout << "tm 1: " << asctime(&fecha_menor) << "n";
- //std::cout << "tm 2: " << asctime(&fecha_mayor) << "n";
- std::cout << "diferencia: " << difftime(epoca2, epoca1) << "n";
- return difftime(epoca2, epoca1);
- }
- Glib::signal_timeout().connect(sigc::mem_fun(*this, &Ventana::actualizar_tiempo), 1000);
- bool Ventana::actualizar_tiempo()
- {
- if(tiempo < 0)
- controlador->entrar_y_salir();
- }
- //Este es otro archivo
- void Controlar::entrar_y_salir()
- {
- //Funcion para iniciar y detener el contador de tiempo
- std::string hora_entrada = "2019-01-18 11:32:00";
- std::string hora_salida = "2019-01-18 11:32:04";
- int tiempo = diferencia_entre_fechas(hora_entrada, hora_salida);
- ....
- }
Add Comment
Please, Sign In to add comment