c++怎么用<time.h>分别获取当前的年,月,日赋值于toyear tomonth today这3个变量中
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
time_t seconds;
struct tm * timeinfo;
int sec,toyear,tomonth,today;
seconds = time (NULL);
timeinfo = localtime ( &seconds );
toyear= timeinfo->tm_year + 1900;
tomonth= timeinfo->tm_mon + 1;
today = timeinfo->tm_mday;
printf(" %d %d %d\n",toyear,tomonth,today);
return 0;
}
#include <stdlib.h>
#include <time.h>
main()
{
time_t seconds;
struct tm * timeinfo;
int sec,toyear,tomonth,today;
seconds = time (NULL);
timeinfo = localtime ( &seconds );
toyear= timeinfo->tm_year + 1900;
tomonth= timeinfo->tm_mon + 1;
today = timeinfo->tm_mday;
printf(" %d %d %d\n",toyear,tomonth,today);
return 0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询