本文共 524 字,大约阅读时间需要 1 分钟。
C++获取当前时间
#include#include using namespace std; int main( ){ time_t now = time(0); cout << "1970 到目前经过秒数:" << now << endl; tm *ltm = localtime(&now); cout << "年: "<< 1900 + ltm->tm_year << endl; cout << "月: "<< 1 + ltm->tm_mon<< endl; cout << "日: "<< ltm->tm_mday << endl; // 北京时区 + 8 int hour = (ltm->tm_hour + 8) % 24 ; cout << "时间: "<< hour << ":"; cout << ltm->tm_min << ":"; cout << ltm->tm_sec << endl;}
1970 到目前经过秒数:1615886914年: 2021月: 3日: 16时间: 17:28:34
转载地址:http://pcmxf.baihongyu.com/