localtime
来自cppreference.com
语法:
#include <ctime> struct tm *localtime( const time_t *time );
函数 localtime() 将日历时间 time 变换为本地时间。
返回的结构体是静态分配的,所以不应该删除。
例如,下面的代码使用几个时间相关的函数来显示当前时间:
time_t theTime; time( &theTime ); // 获取日历时间 tm *t = localtime( &theTime ); // 变换为本地时间 cout << "The time is: " << asctime(t);
上面的代码会显示类似这样的输出:
The time is: Fri Oct 17 08:54:41 2008