[求助]c++中怎样获取系统日期和系统时间
c++中怎样获取系统日期和系统时间,请各位帮忙,谢谢
#include<time.h>
#include<iostream>
using namespace std;
int main()
{
time_t timeval;
timeval=time(NULL);
cout<<"Time as local time is "<<ctime(&timeval)<<endl;
return 0;
}
在VC++中,我们可以借助CTime时间类,获取系统当前日期:
CTime t = CTime::GetCurrentTime(); //获取系统日期
int d=t.GetDay(); //获得几号
int y=t.GetYear(); //获取年份
int m=t.GetMonth(); //获取当前月份
int h=t.GetHour(); //获取当前为几时
int mm=t.GetMinute(); //获取分钟
int s=t.GetSecond(); //获取秒
int w=t.GetDayOfWeek(); //获取星期几,注意1为星期天,7为星期六
这是我之前在百度找到的,应该没错~~~~~~~~