我不明白,为什么这不起作用?PS:我从一些谷歌找到了这段代码!
问题:我不知道为什么它应该工作?这是否也考虑时区?!
1 #include<stdio.h>
2 #include <stdlib.h>
3 #include <string>
4 #include <time.h>
5 int main()
6 {
7 std::string text("10/10/2013 14:01:00");
8 const char* nptr = text.c_str();
9 char* endptr = NULL;
10 time_t seconds_from_epoch = strtoul(nptr, &endptr, 0);
11 if (secs != 0)
12 printf("Secs: %ld\n", secs);
13 if (*nptr != '\0' && endptr && *endptr == '\0') {
14 printf("Secs: %ld\n", secs);
15 } else {
16 printf("Unable to convert\n");
17 }
18 }