Thread: Real time clock

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    204

    Real time clock

    Hi,
    How do I display the system's date and time in real time on a console application? Thanks.

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    #include<cstdlib>

    much like my ex, this is the quick, cheap, and dirty method:

    date and time are basic dos commands if that is what you are looking for

    Code:
    system("date");   //you'll have to make a provision for
                      //when the date command prompts you for a 
                      //new date
    Last edited by The Brain; 03-19-2005 at 07:45 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    204
    I think I need more help...here's what I want to do: I need to create a file on the first second of every new day. I know my program will have to be running all the time and that's not a problem, but I have no idea how to do what I want. Any suggestions?

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Use the task scheduler provided by your platform. For Windows, this can be found under Start Menu->Programs->Accessories->System Tools->Scheduled Tasks.

  5. #5
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    There is a really easy way of doing it, but it isn't the best. On the other hand, there is another way with Win32, but I'm not too sure bout that, so I'll post the other other way for now
    The first way is to do something like this...
    Code:
    #include <fstream>
    
    while(1)
    {
    Sleep( 86400000 ); // This is the millisecond equivilant of 24 hours
      ofstream a_file ( "File.txt" );
      std::a_file << "This will be in the file 'File.txt'.";
      a_file.close();
    }
    This method works, but you need to start it off at midnight for it to work the way it should. Also, include the windows header file to use the Sleep function.
    Last edited by Finchie_88; 03-19-2005 at 11:27 AM.


  6. #6
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    Code:
    #include <ctime>
    
    char *str;
    time_t cur_time = time(NULL);
    //cur_time should be your calaender time (in seconds) from:
    strftime(str, 128, "%A %d %B %H %Y", 0);
    printf("%s", str);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Niche Question: real time stock quotes
    By keira in forum C Programming
    Replies: 0
    Last Post: 03-08-2008, 11:06 AM
  2. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 04:44 AM
  3. Military Time Functions
    By BB18 in forum C Programming
    Replies: 6
    Last Post: 10-10-2004, 01:57 PM
  4. Real time issues
    By athos in forum C++ Programming
    Replies: 13
    Last Post: 04-15-2003, 02:19 PM
  5. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM