System Date

This is a discussion on System Date within the C++ Programming forums, part of the General Programming Boards category; How can I access the system date I tried with dos.h but I wish to know a little simpler method. ...

  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
    zen
    zen is offline
    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
    zen
    zen is offline
    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, 01:17 AM
  2. calculate age from date
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-22-2005, 09:57 AM
  3. Getting system Date
    By Sridar in forum C++ Programming
    Replies: 4
    Last Post: 08-10-2005, 09:51 PM
  4. bad system date
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 04-30-2003, 09:29 AM
  5. reading the system date
    By Alicia in forum C++ Programming
    Replies: 5
    Last Post: 02-13-2002, 03:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21