+ 1
How can I record a time in the variable?
Hello everyone! I was reading about the ctime library and went to write a code, which must to output the time (number of hours, have passed since the 1 January 1970 Year). But when I initialize a variable, and assign to her the time, itâs error when i output the variable using cout. The type of variable is time_t, but i was using and int, and time_t. Help me please! đą
1 Answer
+ 2
#include <iostream>
#include <ctime>
int main()
{
std::time_t t; // Decalre a variable with type time_t
std::time(&t); // use time() function to assign the current time to the variable
std::cout << t << std::endl;
return 0;
}
time() return the number of seconds since 00:00 hours, Jan 1, 1970 UTC.