Thread: getting time from the OS

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    15

    Talking getting time from the OS

    Greetings,
    I need to access the current time from the operating system for use in a project that I am currently working on. I am using VC6 and have tried the time function in time.h but cannot get it to work. Any suggestions or help with the above matter would be greatly appreciated.
    Thx's in advance

    "In order to make an apple pie from scratch you must first create the universe"

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    Try this...

    Code:
    #include <fstream.h>
    #include <time.h>
    
    char* GetTime(void);
    
    int main() {
    
       fstream fso;
       fso.open( "systime.txt", ios::out );
       fso << GetTime();
       fso.close();
       return 0;
    
    }
    
    
    char* GetTime() {
    
       time_t now; 
       time( & now ); 
       struct tm* ptm; 
       ptm = localtime( & now );
       return asctime( ptm );
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Representing floats with color?
    By DrSnuggles in forum C++ Programming
    Replies: 113
    Last Post: 12-30-2008, 09:11 AM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM