#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Help with displaying time please


    Hey guys,

    I am making a simple program (for learning purposes) that has a main goal of gathering 3 sets of information from user;
    -A Starting time
    -A Finishing time
    -Number of people

    *Output
    The program then works out the time between start and finish (for example; 7 hours) then divides it evenly between the number of people. For example: 5 people to complete 5 hours (keep it simple)
    Person 1 will start at 1100 and finish at 1200
    person 2 will start at 1200 and finish at 1300
    ... etc

    I am having an issue with the display of time, I have researched but being very new I am looking for needle in a hay stack.

    So lets say for example the starting time is 1400(24h time) and the program has worked out that each person is required to work 61 minutes (for ease of explanation), I am not sure how to simply have the print function display "1501" appose to "1461"

    Is there something I could use that would allow me to apply a integer to a time function ((if its possible)to designate start time) and then be able to add integers on top of that over and over (as required) with the program applying the math to 'time rules'(60 mins in a hour etc)

    I hope I explained this well enough, any help would be fantastic.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,365
    Rep Power
    1870
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,091
    Rep Power
    2222
    The time functions are prototyped in the header file, time.h .

    Time, which is of type time_t, is the number of seconds since the beginning of time at midnight starting 1970 Jan 01. time.h also defines struct tm whose fields are time units for date and time and the like. There are functions to convert a time_t to a struct tm and a struct tm to a time_t. And functions that will take one or the other and output a string in whatever format you choose.

    Look them up and see what may apply. There should be plenty of examples on-line.

IMN logo majestic logo threadwatch logo seochat tools logo