i have the following code below:
const char* timeformat = "%Y-%m-%d %H:%M:%S";
const int timelength = 20;
char timecstring[timelength];
strftime(timecstring, timelength, timeformat, currentstruct);
cout << "timecstring is: " << timecstring << "\n";
currentstruct is a tm*. The cout is giving me the date in the correct format, but the year is not 2010, but 3910. I know there is something to do with the year cound starting at 1900, but im not sure how to get strftime to recognise this and not add 1900 to the value of 2010 that is there, can anyone help.
Regards
Paul
When you put the year into your
currentstruct, you’re apparently putting in2010, but you need to put in2010-1900.If you retrieve the time from the system and convert to a
struct tmwith something likelocaltime, you don’t need to do any subtraction though, because what it puts into thestruct tmis already the year – 1900. You do need to subtract 1900 when you fill in the year “manually”.