Current date and time as string

后端 未结 6 1861
梦毁少年i
梦毁少年i 2020-12-04 11:09

I wrote a function to get a current date and time in format: DD-MM-YYYY HH:MM:SS. It works but let\'s say, its pretty ugly. How can I do exactly the sam

6条回答
  •  自闭症患者
    2020-12-04 11:47

    you can use asctime() function of time.h to get a string simply .

    time_t _tm =time(NULL );
    
    struct tm * curtime = localtime ( &_tm );
    cout<<"The current date/time is:"<

    Sample output:

    The current date/time is:Fri Oct 16 13:37:30 2015
    

提交回复
热议问题