Thread: About time

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    22

    About time

    time_t a1 = std::time(NULL); // it take the currect time,day,year, ect..

    Ok, But how i can add 30 days on this?

    Thanks in Advance ]

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Code:
    #include <ctime>
    #include <iostream>
    int main()
    {
    	std::time_t a1 = std::time(NULL);
    	struct tm * timeinfo;
    	a1 += 24*60*60*30;//hours*minutes*seconds*days
    	timeinfo = localtime ( &a1 );
    	std::cout << asctime(timeinfo);
    	return 0;
    }
    Two little notes
    it take the currect time,day,year, ect..
    It really takes just seconds elasped since some time in 1970

    And a better variable name then a1 would probably be good
    Last edited by MadCow257; 01-12-2006 at 07:53 PM.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    22
    Thanks for help

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    91
    i thought it was going to be something like, 'about time.. somebody answered my damn question'..lol

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    This isn't the easiest to read, but it brings up some potential issues:
    Time/Date Calculations
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get current time
    By tsubasa in forum C Programming
    Replies: 3
    Last Post: 05-01-2009, 02:03 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 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