Thread: standard time, help.

  1. #1
    Registered User
    Join Date
    Sep 2004

    standard time, help.

    Im not all lost (I hope) but I do not understand the use of
    std::time(0), could anyone please explain
    exactly what it does as the program compiles without the
    use of that function... but the time it displays is not correct.
    (This actually gives a hint about the importantness of std::time(0)
    but what I want is an accurate description).
    #include <iostream>
    #include <ctime>
    int main()
    	int hour, min, sec;
    	time_t now=std::time(0);
    	tm *thetime = std::localtime(&now);
    	hour = thetime->tm_hour;
    	min = thetime->tm_min;
    	sec = thetime->tm_sec;
    	cout << hour << ':' << min << ':' << sec;
    Last edited by antex; 10-19-2004 at 02:57 PM. Reason: mixed swedish and english var names in same code... got compile error ofcourse as for example.. I defined int sec and tried to output sek

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    It returns the current time. The rest of the program (after fixing typos so that it will compile) just interprets the value returned by time(0) so that it is readable for you.

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    I thought time(0) returned the number of milliseconds since January 1, 1970?

    [edit] nevermind, i just noticed the line with std::localtime which changes everything [/edit]

  4. #4
    Registered User
    Join Date
    Sep 2004
    ok, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Execution Time - Rijandael encryption
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2008, 09:25 PM
  2. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 03:41 AM
  3. The new FAQ
    By Hammer in forum A Brief History of
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM