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 7065565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:58:18+00:00 2026-05-28T04:58:18+00:00

In my application,I am getting time input in a variable in string format e.g.

  • 0

In my application,I am getting time input in a variable in string format e.g. Values = '12,12,12'.

Now i need to validate it h<24 M<60 S<60 etc. and i want final output in '%H:%M:%S' format.
To get this i tried datetime.time().

I had 1st tried with values = '12' then '12,12,12'.

In [1]: import datetime

In [2]: values = '12'

In [3]: d = datetime.time(values)

TypeError  Traceback (most recent call last)
/mypc/test/<ipython console> in <module>()
TypeError: an integer is required

In [4]: d = datetime.time(int(values))

In [5]: d
Out[5]: datetime.time(12, 0)

In [6]: d.strftime('%H:%M:%S')
Out[6]: '12:00:00'

In [7]: s = d.strftime('%H:%M:%S')

In [8]: s
Out[8]: '12:00:00'

In [9]: values = '12,12,12'

In [10]: d = datetime.time(int(values))

ValueError: invalid literal for int() with base 10: '12,12,12'

But it works as below.

In [24]: datetime.time(12,12,12).strftime('%H:%M:%S')
Out[24]: '12:12:12'

So problem is that datetime.time() is taking input as integer and '12,12,12' string cannot be converted in int.

Is there any other way(otherthan regexp) to do the validation for only Hr:M:S.

  • 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-05-28T04:58:19+00:00Added an answer on May 28, 2026 at 4:58 am

    You have to unpack the values:

    >>> values = '12,12,12'
    >>> values = ast.literal_eval(values)
    >>> datetime.time(*values)
    datetime.time(12, 12, 12)
    

    This last statement will raise an error if the time given is invalid.

    To avoid problems with zero-padded numbers, as “wim” pointed, it’s possible to change the second line to:

    values = (int(i) for i in values.split(','))
    

    or

    values = map(int, values.split(','))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a long time hobbyist programmer interested in getting into web application development. I
hi my application contains SQLite .My application some time getting the following error java.lang.RuntimeException:
Am using datagrid in my windows application, its getting more time to load datas(13
I'm having a hard time getting what I want out of the python subprocess
In one of our application im getting an exception that i can not seem
in my application I am getting an exception: MyApp(38431,0xa004ffa0) malloc: *** error for object
While creating the setup for VB.net application I am getting the following warning: Warning
I am tried deploying .cod,.alx.jar files on blackberry simulator 8100;the application is not getting
I'm getting an error when my application starts. It appears to be after it's
I keep getting this NPE in my application and I can't seem to get

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.