time_t now=time(NULL); std::cout<<ctime(&another_time);tm* ltm = localtime(&now);

#include <iostream>
#include <iomanip>
#include <ctime>
#include<windows.h>
int main() {
    time_t now = time(NULL);
    tm* ltm = localtime(&now);
    std::cout<<ctime(&now);
    std::cout << "Year: " << 1900 + ltm->tm_year << std::endl;
    std::cout << "Month: " << 1 + ltm->tm_mon << std::endl;
    std::cout << "Day: " << ltm->tm_mday << std::endl;
    std::cout << "Time: " << std::setw(2) << std::setfill('0') << ltm->tm_hour << ":";
    std::cout << std::setw(2) << std::setfill('0') << ltm->tm_min << ":";
    std::cout << std::setw(2) << std::setfill('0') << ltm->tm_sec << std::endl;
    Sleep(1220);
    time_t another_time=time(0);
    std::cout<<ctime(&another_time);
    double gap=difftime(another_time,now);
    std::cout<<"gap"<<gap<<"s"<<std::endl;
    return 0;
}

#ifndef _TM_DEFINED
#define _TM_DEFINED
  struct tm {
    int tm_sec;
    int tm_min;
    int tm_hour;
    int tm_mday;
    int tm_mon;
    int tm_year;
    int tm_wday;
    int tm_yday;
    int tm_isdst;
  };
#endif

posted @ 2023-04-18 22:06  Logic_Han  阅读(42)  评论(0编辑  收藏  举报