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
| #include <stdio.h>
#include <time.h>
#include <string.h>
double getDate( char *mdate);
int main() {
char *test = "23/06/2003";
double tmp;
printf("Orig : %s\n", test);
tmp = getDate(test);
printf("TS : %f\n", tmp);
return 1;
}
double getDate( char *mdate) {
struct tm t;
double tbday = 0;
char s[10];
printf("Having date: %s\n", mdate);
if (sscanf(mdate, "%d/%d/%d", &t.tm_mday, &t.tm_mon, &t.tm_year) == 3) {
printf("Y verification: %d\n", t.tm_year);
t.tm_mon -= 1;
t.tm_year -= 1900;
t.tm_hour = 12;
t.tm_min = 0;
t.tm_sec = 0;
strftime(s, 10, "%d/%m/%Y", &t);
printf("Gives : %s\n", s);
if (strcmp(mdate, s) == 0) {
tbday = mktime(&t);
}
}
return tbday;
} |
Partager