Thread: Tracking the time w/c++

  1. #1
    Registered User
    Join Date
    Sep 2003

    Tracking the time w/c++

    Ok, i'm trying to write a quick program that will grab the time now and then keep track of how many hours it's been since the time was first grabbed up to a certain # of hours.

    My plan is to have the program store the time in an ini file for access later. All I need to know though is how to make C++ understand what time it is now, and the next time I open the program, how many hours it's been since I grabbed the initial time, in 30 minute increments if possible.

    Any tips / links to tutorials / guidance is appreciated.

    Thanks in advance

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    You could consider using time() from <ctime>. The FAQ says something about Working with dates and times.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Take a look at the date & time FAQ.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Thanks a lot to both of you! Good info there.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    In addition, Boost has a Date_Time library that makes working with dates and times a lot easier.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 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