zoukankan      html  css  js  c++  java
  • 如何利用C++的time头文件获取系统时间

    C++提供了time.h头文件进行时间编辑操作,可以把时间格式化进tm结构体,方便使用。MFC框架中的ctime类就是基于time.h封装的。


    代码样例:


    #include <iostream>
    #include <cstdio>
    #include <time.h>
    
    using namespace std;
    
    int main(void)
    {
    	time_t t = time(NULL);   //获取当前时间句柄
    	tm *pt = localtime(&t);  //将时间句柄转换为tm时间结构体
    	int year = pt->tm_year+1900;
    	int month = pt->tm_mon+1;
    	int day = pt->tm_mday;
    	int hour = pt->tm_hour;
    	int minute = pt->tm_min;
    	int second = pt->tm_sec;
    	printf("%d-%d-%d %02d:%02d:%02d
    
    ",year,month,day,hour,minute,second);
    	return 0;
    }


  • 相关阅读:
    hero
    今年暑假不AC
    Who's in the Middle
    A Simple Problem with Integers
    I hate it
    敌兵布阵
    Ordering Tasks
    Points on Cycle
    食物链
    c++ 14.0下载地址
  • 原文地址:https://www.cnblogs.com/csnd/p/12897046.html
Copyright © 2011-2022 走看看