像这样的东西怎么样:
char d1[] = "2013-02-01 12:56:09";
char d2[] = "2013-01-02 13:14:27";
char *parts1[6];
char *parts2[6];
char *p1, *p2;
for(int i = 0; i < 6; i++)
{
parts1[i] = strtok_r(i?0:d1, "-: ", &p1);
parts2[i] = strtok_r(i?0:d2, "-: ", &p2);
}
struct tm t1, t2;
t1.year = strtol(parts1[0], 0, NULL);
t1.month = strtol(parts1[1], 0, NULL);
t1.day = strtol(parts1[2], 0, NULL);
t1.hour = strtol(parts1[3], 0, NULL);
t1.hour = strtol(parts1[4], 0, NULL);
t1.hour = strtol(parts1[5], 0, NULL);
t2.year = strtol(parts2[0], 0, NULL);
t2.month = strtol(parts2[1], 0, NULL);
t2.day = strtol(parts2[2], 0, NULL);
t2.hour = strtol(parts2[3], 0, NULL);
t2.hour = strtol(parts2[4], 0, NULL);
t2.hour = strtol(parts2[5], 0, NULL);
time_t tt1, tt2;
tt1 = mktime(&t1);
tt2 = mktime(&t2);
double diff = difftime(tt1, tt2) / 60; // Seconds -> make it minutes.