📅  最后修改于: 2020-10-13 04:12:01             🧑  作者: Mango
time() 函数在
time_t time(time_t* arg);
的时间() 函数的指针time_t
对象作为其参数,并返回当前日历时间作为类型的值time_t
。
如果arg
不是空指针,则返回的值也将存储在arg
指向的对象中。
#include
#include
using namespace std;
int main()
{
time_t current_time;
current_time = time(NULL);
cout << current_time << " seconds has passed since 00:00:00 GMT, Jan 1, 1970";
return 0;
}
运行该程序时,输出为:
1489924627 seconds has passed since 00:00:00 GMT, Jan 1, 1970
#include
#include
using namespace std;
int main()
{
time_t current_time;
// Stores time in current_time
time(¤t_time);
cout << current_time << " seconds has passed since 00:00:00 GMT, Jan 1, 1970";
return 0;
}
运行该程序时,输出为:
1489924627 seconds has passed since 00:00:00 GMT, Jan 1, 1970