by doing this u are replacing the prefilled values of tm_mon, tm_year and tm_mday with those in month, year and day (those u created urself... - as bazzy explained in his post)...
= : takes the right operand and assing its val to the left...
so u got to turn things to... year = timeinfo->tm_year; (understood?)
but: even if u do so the program would show
0 , 110 , [the current day]
...
this is because the values in your tm-structure are filled as in the following link (read the table carefully - i didnt do this the last time^^) http://cplusplus.com/reference/clibrary/ctime/tm/
Yes... I got it. I knew I had something wrong in the timeinfo->tm_???? = ????; lines
tm_year years since 1900
and
tm_mon months since January 0-11
So I am guessing a couple if statements would fix the month problem and I would need a new variable to
do var = year + 1990;
but then if i did elapsed time with that it would only go from 1900 to present how would i fix that?
also I just noticed another problem... If I was doing elapsed time, Then DST would get in the way every year and mess up the results. It could be off by more than a couple days. Is it possible to use tm_isdst to fix this?
Or does loosing an hour and then gaining back another cancel this out?
why a couple of if-statements... just add 1 to your month :D... if u want to write out the month´s name use an switch-control structure...
beginner at programming wrote:
also I just noticed another problem... If I was doing elapsed time, Then DST would get in the way every year and mess up the results. It could be off by more than a couple days
#include <ctime>
#include <iostream>
usingnamespace std;
// GLOBAL VARIABLES
int month,year,day,year1,month1;
int main () //main
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
month = timeinfo->tm_mon;
year = timeinfo->tm_year;
day = timeinfo->tm_mday;
year1 = year + 1990;
// month fixed
month1 = month + 1;
/* Prints The correct date */
cout << month1 <<"/" << day << "/" <<year1 << endl;
system ("PAUSE");
return 0;
} // end of main