获取系统实时时间

获取系统实时时间

#include <stdio.h>
#include <time.h>

#include <iostream>
int main() {
    time_t tt;
    time(&tt);
    tt = tt + 8 * 3600;   // transform the time zone
    tm* t = gmtime(&tt);  //返回tm结构的格林尼治时间
    std::cout << tt << std::endl;
    char cDate[25];
    sprintf(cDate, "%d-%02d-%02d_%02d:%02d:%02d.ts\n", t->tm_year + 1900,
            t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
    std::string date(cDate);  //构造函数,用C字符数组初始化
    std::cout << date << std::endl;
}

 

posted @ 2021-03-12 10:35  朱果果  阅读(114)  评论(0编辑  收藏  举报