Currently i'm trying to get the date using the localtime_s function but i'm getting an error. The problematic part of my code is
time_t rawtime;
struct tm timeinfo;
localtime_s(&timeinfo, &rawtime);
This isn't doing anything yet, i'm assuming there's something I need to add to actually reference timeinfo i just don't know what it is?
It's more likely that the OP is using Microsoft's localtime_s:
errno_t localtime_s(struct tm* _tm, const time_t *time);
https://msdn.microsoft.com/en-us/library/a442x3ye.aspx <- this by the way gives a usage example
(C's localtime_s adopted the function signature from POSIX localtime_r)
Last edited on
The code now runs but the output is "-1/0/1969" rather than the current date.
The rest of the code is below:
time_t rawtime;
struct tm timeinfo;
localtime_s(&timeinfo, &rawtime);
int month = 1 + timeinfo.tm_mon,
day = timeinfo.tm_mday,
year = 1970 + timeinfo.tm_year;
string currentDate = to_string(month) + "/" + to_string(day) + "/" + to_string(year);