-1

So i have a variable that needs to be displayed as a time of day, i.e 3:02, and then make calculations off of that variable, i.e add 7 to the first variable, wellington,and have it displayed as 3:09. This is a simple question, and it doesn't need to go into the datetime is there a way i can do it, without datetime?

def traintimes():
    crofton = wellington + 7
    ngaio = crofton + 2
    awarua = ngaio + 2
    simla = awarua + 2
    boxhill = simla + 1
    kandallah = boxhill + 2
    raroa = kandallah + 2
    johnsonville = raroa + 2
    print ("Wellington:",wellington,"Crofton Downs:",crofton,"Ngaio:",ngaio,"Awarua Street:",awarua,"Simla Crescent:",simla,"Box Hill:",boxhill,"Kandallah:",kandallah,"Raroa:",raroa,"Johnsonville:",johnsonville)
wellington = int("3:02")
traintimes ()
wellington = int("3:28")
traintimes()
wellington = int("3:40")
traintimes()
Nash
  • 69
  • 1
  • 1
  • 6
  • 1
    Possible duplicate of [What is the standard way to add N seconds to datetime.time in Python?](http://stackoverflow.com/questions/100210/what-is-the-standard-way-to-add-n-seconds-to-datetime-time-in-python) – Morgan Thrapp Feb 11 '16 at 19:14

1 Answers1

0

You want to use the datetime module instead of working with ints. Use timedelta to make the calculations.

Example:

import datetime

current_time = datetime.datetime.now()

crofton = current_time + datetime.timedelta(minutes=7)

Working with time can be very difficult without the correct library, I suggest taking the time to read the datetime documentation.

Also, this article is pretty much required reading for all programers who work with time.

Sam Myers
  • 2,112
  • 2
  • 15
  • 13