Time Calculation

This is a discussion on Time Calculation within the Tech Board forums, part of the Community Boards category; im sorry to ask this im sure its a very simple calculation but its really frustrating me if i take ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1

    Time Calculation

    im sorry to ask this im sure its a very simple calculation but its really frustrating me

    if i take 2 int variables the 1st is a time such as 1345 (1:45pm)
    the 2nd a duration of time such as 530 (5hours 30min)
    how do i add them together and get the correct time of 1915 (6:15pm)?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    > if i take 2 int variables the 1st is a time such as 1345 (1:45pm)
    Convert to minutes - as 13*60+45

    Then do the reverse to recover hours and minutes when you're done.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. Representing floats with color?
    By DrSnuggles in forum C++ Programming
    Replies: 113
    Last Post: 12-30-2008, 09:11 AM
  3. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 11:42 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

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