Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8842769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:02:53+00:00 2026-06-14T11:02:53+00:00

I have a method which takes two variables: Current Time Minutes The method is

  • 0

I have a method which takes two variables:

  • Current Time
  • Minutes

The method is pretty simple. The user inputs the two values, the first being a string eg. ’23:01′
The second being an integer eg 50. So the method calculates the new time by adding the two together, so the new time should be 23:51.
I get this to work, however when the time becomes 24:01 + 60 it becomes 25:01 which is an incorrect time.
How do I simply use the time method in python to add the times?
Here is my code so far which throws up an error

import time
class timeCalc(object):
    def nextTime(self, time, minutes):
        t = time.split(':')
        mins = int(t[0]) * 60 + int(t[1]) + minutes
        h = str(mins/60)
        m = str(mins%60)
        if len(h) == 1:
            h = '0' + h
        if len(m) == 1:
            m = '0' + m
        nTime = time.strptime(h + ':' + m, "%H:%M")
        print nTime

ts = timeCalc()
ts.nextTime('23:01',60)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:02:54+00:00Added an answer on June 14, 2026 at 11:02 am

    you don’t need parse the time parameter on that way, you can do:

    Import datetime
    class timeCalc(object):
        def nextTime(self, time, minutestoadd):
            base_time = datetime.datetime.strptime(time, "%H:%M")
            minutesobj = datetime.timedelta(minutes = minutestoadd)
            newtime = basetime + minutesobj
            print newtime.time()
    

    Line 4:
    You format the ‘time’ parameter to a datetime object with format %H:%M called base_time
    Line 5:
    You convert the minutestoadd parameter to a compatible object format to add
    Line 6:
    The sum of both datetime object values
    Line 7:
    Print the result on a format like 23:40:00

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an extension method which takes in two list and compares them for
I have a method which takes a list and do some processing on it
i have a method which takes in a DotNetOpenAuth (formally known as DotNetOpenId) Response
I have a method which takes a directory path as a string. In the
I have a method which takes an array of strings as parameter and queries
I have an ATL COM component method which takes a BSTR as an in
I have the following method, which takes in the name of a file as
Say I have a method called GetCatsByColor which takes a color as a string,
I have a permissions attribute which takes a list of enum values for roles:
In Java, suppose I have a method that takes in two lists of integers,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.