localtime:
方法一:
#include <windows.h>
int main()
{
SYSTEMTIME systm;
GetLocalTime(&systm);
cout<<systm.wYear<<"-"<<systm.wMonth<<"-"<<systm.wDay<<" "<<
systm.wHour<<":"<<systm.wMinute<<":"<<systm.wSecond;
return 0;
}
方法二:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t nowtime;
struct tm* ptm;
time(&nowtime);
ptm = localtime(&nowtime);
cout<<ptm->tm_year + 1900<<"-"<<ptm->tm_mon + 1<<"-"<<ptm->tm_mday<<" "
<<ptm->tm_hour<<":"<<ptm->tm_min<<":"<<ptm->tm_sec;
return 0;
}
localtime_s的用法:
将上面第二种方法改一下变成:localtime_s(struct tm * _Tm, const time_t * _Time)即可
time_t nowtime;
struct tm ptm;time(&nowtime);
localtime_s(&ptm,&nowtime);
然后就可以进行ptm对此时此刻时间的调用了
此时ptm是一一个结构体,我没用指针了。