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
| #include <stdio.h> // important pour le printf !!
#include <time.h>
int main()
{
char *jour[]={"dimanche", "lundi","mardi","mercredi","jeudi","vendredi","samedi"};
int y,m,d;
struct tm t;
time_t tt;
printf("date ? (ex : 25/12/2003) ") ;
scanf("%d/%d/%d", &d, &m, &y) ;
y = y - 1900 ;
t.tm_sec=0;
t.tm_min=0;
t.tm_hour=0;
t.tm_mday=d;
t.tm_mon=m-1;
t.tm_year=y;
tt=mktime(&t) ;
if (tt==-1){
fprintf(stderr,"Error mktime, cannot consider this date\n");
exit(1);
}
t=*localtime(&tt) ;
printf("date : %s %.2d/%.2d/%.4d\n", jour[t.tm_wday], d, m, (y+1900));
return 0;
} |
Partager