Thread: System Date

  1. #1
    Unregistered
    Guest

    Question System Date

    How can I access the system date I tried with dos.h but I wish to know a little simpler method.
    Please help.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    There's the function time() that takes a time_t struct in time.h.

  3. #3
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Sorry, time_t is a long int not a struct, and the time function takes a pointer to this long int. You'll have to use other functions declared in time.h to format this value.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    struct tm * timestruct;
    time_t totalseconds;
    char * timestring;

    time(&totalseconds) ; //Stores the long time in totalseconds
    timestruct = localtime(&totalseconds); //Creates a struct containing time data
    timestring = asctime(timestruct); //Creates a character string representing the time
    cout << timestring << "\n"; //Outputs the time

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. casting the system exstracted date into seperate ints
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-30-2005, 12:17 AM
  2. calculate age from date
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-22-2005, 08:57 AM
  3. Getting system Date
    By Sridar in forum C++ Programming
    Replies: 4
    Last Post: 08-10-2005, 08:51 PM
  4. bad system date
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 04-30-2003, 08:29 AM
  5. reading the system date
    By Alicia in forum C++ Programming
    Replies: 5
    Last Post: 02-13-2002, 03:18 PM