通过time()函数获取时间戳

2021-10-21 15:06:51 浏览数 (1)

取走直接用,当个 demo 挺好的。

代码语言:javascript复制
#include <iostream>
#include <time.h>
#include <unistd.h>
using namespace std;

int main()
{
    string str;
    time_t myt = time(NULL);
    cout << "sizeof(time_t) is: " << sizeof(time_t) << endl;
    cout << "myt is :" << myt << endl;

    sleep(1);

    time_t t;
    time(&t);
    cout << "t is:" << t << endl;

    cout<<t-myt<<endl;

    str = to_string(myt);
    cout<<str<<endl;
    cout<<str.size()<<endl;
}

0 人点赞