View Full Version : quale funzione fa questa cosa?
io ho un valore che mi dice in secondi il tempo che il pc è acceso, mi serve una funzione che mi restituisca dati tot secondi, il tempo in GG-HH-MM-SS!
RaouL_BennetH
29-04-2005, 12:00
io ho un valore che mi dice in secondi il tempo che il pc è acceso, mi serve una funzione che mi restituisca dati tot secondi, il tempo in GG-HH-MM-SS!
in che linguaggio?
Ziosilvio
29-04-2005, 12:12
Con un po' di aritmetica modulare te ne puoi ricavare subito una tu.
La logica è questa: tu hai T secondi, ma T secondi sono T/60 minuti più T%60 secondi; eccetera. Alla fine usi una printf per scriverlo nel formato che vuoi tu.
RaouL_BennetH
29-04-2005, 12:24
considera questo semplice esempio:
#include <time.h>
#include <stdio.h>
int main()
{
time_t tempo;
tempo=time(NULL);
printf("\nIl formato attuale è: %s\n", asctime(localtime(&tempo));
return 0;
}
ilsensine
29-04-2005, 12:37
Come ti dicevo nell'altro thread, bastano alcune divisioni:
int secs = getSecs();
int hh;
int mm;
int gg;
gg = secs / (60*60*24);
hh = (secs / (60*60)) % 24;
mm = (secs / 60) % 60;
secs %= 60;
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.