這裏是我如何做到這一點在Linux中,但在Windows中我沒有strptime
函數任何人都可以幫助我解決這個問題?如何在Windows中與C進行比較
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
time_t to_seconds(const char *date)
{
struct tm storage = {0, 0, 0, 0, 0, 0, 0, 0, 0};
char *p = NULL;
time_t retval = 0;
p = (char *) strptime(date, "%d-%b-%Y", &storage);
if (p == NULL)
{
retval = 0;
}
else
{
retval = mktime(&storage);
}
return retval;
}
int main(int argc, char** argv)
{
time_t d1 = to_seconds("16-Jun-2015");
time_t d2 = to_seconds("13-Jun-2015");
if(d1 > d2)
{
printf("date 1 > date 2");
}
}
爲什麼投'(字符*)STRP ...'?另外,'strptime()'不是標準的。 –
你是什麼意思? –
我的意思是,當它可用時,不需要將'strptime()'強制轉換爲'char *',並且它不在Windows上,因爲它不是標準函數。爲什麼這種格式,你從哪裏得到日期?這是一個文件嗎? –