- 论坛徽章:
- 0
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
void str_to_local_t(char* str_date);
int main(int argc, char** argv)
{
char* str="2007-1-1";
str_to_local_t(str);
return 0;
}
void str_to_local_t(char* str_date)
{
char* str;
struct tm tm_date;
time_t t_date;
str = strtok(str_date, "-");
if(str)
{
tm_date.tm_year = atoi(str);
}
str = strtok(NULL, "-");
if(str)
{
tm_date.tm_mon = atoi(str) - 1;
}
str = strtok(NULL, "-");
if(str)
{
tm_date.tm_mday = atoi(str);
}
tm_date.tm_hour=0;
tm_date.tm_min=0;
tm_date.tm_sec=1;
tm_date.tm_isdst=0;
printf("%d-%d-%d\n",tm_date.tm_year, tm_date.tm_mon, tm_date.tm_mday);
t_date = mktime(&tm_date);
printf("%d\n", t_date);
}
编译过后,输入为-1;
那位大侠帮帮我。 |
|