1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| int calcul_age(void)
{
time_t now;
struct tm tmdate_value,*tmdate_now;
double corrected_received_age;
printf("debut calcul_age:\n");
/*if(!formatage_heure(struct_cache,"Date",&tmdate_value))
return 0;
*/
tmdate_value.tm_mon = 11; /* mois */
tmdate_value.tm_mday = 12; /* jour */
tmdate_value.tm_hour = 10; /* heure */
tmdate_value.tm_min = 12; /* minute */
tmdate_value.tm_sec = 15; /* seconde */
tmdate_value.tm_year = 2000-1900; /* annee 2000= 1900 + 100 annees */
time(&now); // date et heure actuel
// convertit la date now en une représentation struct tm exprimée en Temps Universel (GMT)
if(gmtime_r (&now,tmdate_now) == NULL)
perror("gmtime_r");
printf("date now GMT:\n");
/* Affiche la date et l'heure courante (format français) */
printf ("Nous sommes %s, ", NomJourSemaine[tmdate_now -> tm_wday]);
printf ("le %02u %s %04u, ", tmdate_now -> tm_mday, NomMois[tmdate_now -> tm_mon], 1900 +tmdate_now -> tm_year);
printf ("et il est %02uh %02umin %02usec.\n", tmdate_now -> tm_hour, tmdate_now -> tm_min, tmdate_now -> tm_sec);
printf ("\n");
/* Affiche la date et l'heure courante (format français) */
printf("date cache:\n");
printf ("le %02u %s %04u, ", tmdate_value.tm_mday, NomMois[tmdate_value.tm_mon], 1900 +tmdate_value.tm_year);
printf ("et il est %02uh %02umin %02usec.\n", tmdate_value.tm_hour, tmdate_value.tm_min,tmdate_value.tm_sec);
printf ("\n");
corrected_received_age=mktime(&tmdate_value);
printf("%.0f\n",corrected_received_age);
corrected_received_age=mktime(tmdate_now);
printf("%.0f\n",corrected_received_age);
//corrected_received_age=difftime(mktime(tmdate_now),mktime(&tmdate_value));
//printf("%.0f\n",corrected_received_age);
//printf("La difference est : %.0f\n\n",difftime (mktime(tmdate_now), mktime(&tmdate_value)));
// time_t mktime (struct tm *tm);
//difftime (today, mktime (&date_cache))
//double difftime (time_t time1, time_t time0); |
Partager