日期:2014-05-16 浏览次数:20911 次
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, const char *argv[])
{
char szDateNow[20];
struct tm curtime;
time_t t = time( NULL ); //get systime
localtime_r( &t, &curtime); //转换时间格式
strftime( szDateNow, sizeof(szDateNow), "%Y-%m", &curtime);
printf("%%Y-%%m is %s.\n", szDateNow);
strftime( szDateNow, sizeof(szDateNow), "%04Y-%02m", &curtime);
printf("%%04Y-%%02m is %s.\n", szDateNow);
exit(0);
}