How to get current time and date in C++?

后端 未结 24 1926
刺人心
刺人心 2020-11-22 06:55

Is there a cross-platform way to get the current date and time in C++?

24条回答
  •  迷失自我
    2020-11-22 07:29

    You can also directly use ctime():

    #include 
    #include 
    
    int main ()
    {
      time_t rawtime;
      struct tm * timeinfo;
    
      time ( &rawtime );
      printf ( "Current local time and date: %s", ctime (&rawtime) );
    
      return 0;
    } 
    

提交回复
热议问题