1
我不知道如何設置當前年份strptime
,只有在輸入字符串中沒有設置。如何在C中設置當前年份
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
struct tm tm;
char buffer [80];
// year not set, so use current
char *str = "29-Jan";
if (strptime (str, "%d-%b", &tm) == NULL)
exit(EXIT_FAILURE);
if (strftime (buffer,80,"%Y-%m-%d",&tm) == 0)
exit(EXIT_FAILURE);
// prints 1900-01-29 instead of 2014-01-29
printf("%s\n", buffer);
return 0;
}
非常簡單。謝謝! – user1024718