time_t t = time(0);
struct tm *now = localtime(&t);
With the code above, I can simply get the date like this:
int yearNow = (now.tm_year + 1900), monthNow = (now.tm_mon + 1), dayNow = now.tm_mday
but Visual Studio 2015 gives me error on localtime
, ask me to use localtime_s
instead. Below is my code with using localtime_s
:
time_t rawtime;
struct tm now;
localtime_s(&now, &rawtime);
But the problem is, how do I get the actual current year, month, day in int
?
I print the variable with this code: cout << now.tm_year << " " << now.tm_mon << " " << now.tm_mday;
but the output is -1 -1 -1