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
56
57
58
|
#include <time.h>
#include <stdio.h>
#include <string.h>
void ReadMonth(const char *month)
{
tm value = {0};
if(strptime(month, "%b", &value))
{
printf("%s: %d\n", month, value.tm_mon);
}
}
int main() {
struct tm tm;
char *ptr = strptime("17410105012000", "%H%M%S%d%m%Y", &tm);
printf(
"%s: %s, %d/%d/%d %d:%d:%d", (ptr != NULL && *ptr == '\0') ? "OK" : "ERR",
tm.tm_wday == 0
? "Sun"
: (tm.tm_wday == 1
? "Mon"
: (tm.tm_wday == 2
? "Tue"
: (tm.tm_wday == 3
? "Wed"
: (tm.tm_wday == 4
? "Thu"
: (tm.tm_wday == 5
? "Fri"
: (tm.tm_wday == 6 ? "Sat"
: "ERR")))))),
tm.tm_mon + 1, tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min,
tm.tm_sec);
printf("\n");
ReadMonth("jan");
ReadMonth("january");
ReadMonth("feb");
ReadMonth("february");
ReadMonth("march");
ReadMonth("mar");
ReadMonth("april");
ReadMonth("may");
ReadMonth("may");
ReadMonth("june");
ReadMonth("jul");
ReadMonth("august");
ReadMonth("september");
ReadMonth("oct");
ReadMonth("nov");
ReadMonth("november");
ReadMonth("december");
return 0;
}
|