关于 time.h

https://www.runoob.com/cprogramming/c-standard-library-time-h.html

#include <iostream>
#include <ctime>

using namespace std;

int main()
{
    struct tm t;    //tm结构指针
    char stTmp[32];
    time_t now;        //声明time_t类型变量
    now = time(NULL);//获取系统日期和时间   time(&now); 
    localtime_s(&t, &now);    //获取当地日期和时间
    cout<<t.tm_year + 1900<<"年   ";
    cout<<t.tm_mon + 1<<"月   ";
    cout<<t.tm_mday<<"日   ";
    cout<<"周 "<<t.tm_wday<<"  ";//为了输出好看。。
    cout<<t.tm_hour<<"时   ";
    cout<<t.tm_min<<"分   ";
    cout<<t.tm_sec<<"秒";
    return 0;
}

 

//与time_t 相比,还有一个clock_t,是在记录cpu时间上使用的,两者要分清。

posted on 2020-01-27 23:01  夜隳·依子  阅读(174)  评论(0)    收藏  举报