| 12
 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
 
 |  
 #define NB_TIME_ARGS 6
 
int main (int argc, char** argv)
{
    time_t tmt = 0;
    struct tm t = {0};
 
    char str[100];
 
    /* date - heure courante */
 
    time (&tmt);
    strftime(str, sizeof(str)-1, "%d/%m/%Y %H:%M:%S", localtime (&tmt));
 
    /* récupération des valeurs */
 
    if (NB_TIME_ARGS == sscanf(str, "%02d/%02d/%04d %02d:%02d:%02d",
                                &t.tm_mday, &t.tm_mon, &t.tm_year,
                                &t.tm_hour, &t.tm_min, &t.tm_sec))
 
    {
         /* correction des valeurs */
        t.tm_year -= 1900;
        t.tm_mon--;
        t.tm_isdst = 1; /* gestion heure été / hivers */
 
        tmt=mktime(&t);
 
         /* on ajoute 1 heure  pour le test */
 
        tmt+=3600;
 
         /* reconversion en chaine de charactères */
        strftime(str, sizeof(str)-1, "%d/%m/%Y %H:%M:%S", localtime(&tmt));
 
        printf(str);
    }
 
    return 1
} | 
Partager