: : : : : : : : hello.
: : : : : : : : Im planning to write a program wherein i can get the present time ( Year/Month/Day , Hour.min. sec )and display it. Do any of you have a sample program or anything regarding this that can be of help?
: : : : : : : : This time will be used making a filename for a logfile.
: : : : : : : :
: : : : : : : : thanks,
: : : : : : : : DeAndrei
: : : : : : : :
: : : : : : : I have a whitepaper back book called "THE TURBO C++ TRILOGY A Complete Programmer's Manual" by Eric P. Bloom. It has alot of great stuff on conversions and stuff. I can get you a clock routine with hands and graphics and stuff.
: : : : : : :
: : : : : : How can i avail that book?
: : : : : :
: : : : : i got it on amazon.com for like 10 us$
: : : : :
: : : : ok. thanks. actually i am just interested on getting that part of the program on my original email. I have already displayed the time just now using this program on this link.
: : : :
: : : :
http://www.cplusplus.com/ref/ctime/asctime.html
: : : :
: : : : now what im interested is getting each of that value (month, day, year.. etc.) and storing it on a variable. so i can monitor if one hour has already passed.
: : : :
: : :
: : : In your program you create a pointer to struct tm.
: : :
: : : struct tm * timeinfo;
: : : time ( &rawtime );
: : : timeinfo = localtime ( &rawtime );
: : :
: : :
: : : You have everything you need in timeinfo.
: : :
: : :
http://www.cplusplus.com/ref/ctime/tm.html
: : :
: : :
http://cplus.about.com/od/beginnerctutoria1/l/aa041602a.htm
: : :
: : :
: : :
: : Thanks a lot! that link really hepled me.
: : My next task is adding that date to the filename of the logfile.
: : ex. if filename[100] = "logfile" it would become filename[100]= "logfile__09_28_2005"
: :
: : Any hints on this?
: :
: :
: :
:
:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt_string_manipulation.asp
:
:
what am i doing wrong?
static char Time[23];
time_t rawtime;
struct tm *timeinfo;
void get_time()
{
/* Get current time */
time ( &rawtime );
/* convert rawtime value to tm structure */
timeinfo = localtime ( &rawtime );
Time[0,1,6,9,12,13,16,19] = '_';
Time[2] = (timeinfo->tm_year + 1900);
Time[7] = (timeinfo->tm_mon);
Time[10] = (timeinfo->tm_mday);
Time[14] = (timeinfo->tm_hour);
Time[17] = (timeinfo->tm_min );
Time[20] = (timeinfo->tm_sec );
Time[22] = '\0';
printf("Time: %s\n", Time);
}
when i run the code the only display is (Time: )
im expecting Time: __2005_09_30__05_23_54
no time is displaying.
any suggestions?