getting the time - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

getting the time

DeAndreiDeAndrei Posts: 18Member
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

Comments

  • CyGuyCyGuy Posts: 312Member
    : 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.
  • DeAndreiDeAndrei Posts: 18Member
    : : 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?
  • CyGuyCyGuy Posts: 312Member
    : : : 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$
  • DeAndreiDeAndrei Posts: 18Member
    : : : : 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.
  • CyGuyCyGuy Posts: 312Member
    [b][red]This message was edited by CyGuy at 2005-9-26 19:14:28[/red][/b][hr]
    : : : : : 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.
    :
    time.h and dos.h have those functions, or there may be a registry key to access things.
    that site is awsome... wish i had links like that... one day... i might

  • dwccgcdwccgc Posts: 576Member
    : : : : : 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.
    [code]
    struct tm * timeinfo;
    time ( &rawtime );
    timeinfo = localtime ( &rawtime );
    [/code]

    You have everything you need in timeinfo.

    http://www.cplusplus.com/ref/ctime/tm.html

    http://cplus.about.com/od/beginnerctutoria1/l/aa041602a.htm


  • DeAndreiDeAndrei Posts: 18Member
    : : : : : : 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.
    : [code]
    : struct tm * timeinfo;
    : time ( &rawtime );
    : timeinfo = localtime ( &rawtime );
    : [/code]
    :
    : 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?


  • dwccgcdwccgc Posts: 576Member
    : : : : : : : 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.
    : : [code]
    : : struct tm * timeinfo;
    : : time ( &rawtime );
    : : timeinfo = localtime ( &rawtime );
    : : [/code]
    : :
    : : 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

  • DeAndreiDeAndrei Posts: 18Member
    : : : : : : : : 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.
    : : : [code]
    : : : struct tm * timeinfo;
    : : : time ( &rawtime );
    : : : timeinfo = localtime ( &rawtime );
    : : : [/code]
    : : :
    : : : 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] = '';
    printf("Time: %s
    ", 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?
  • Ed HallEd Hall Posts: 395Member
    : 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] = '';
    : printf("Time: %s
    ", 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?
    :
    [blue]This is just a guess, looking the code over quickly, but you aren't taking into account that the values returned are numeric. If you get 0-11 for the months and plug that value directly into a string, you will end up with an unprintable character and unpredictable results.

    Take Care,
    Ed[/blue]

Sign In or Register to comment.