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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:25:42+00:00 2026-06-18T11:25:42+00:00

Suppose you have time in this format: a = […, 800.0, 830.0, 900.0, 930.0,

  • 0

Suppose you have time in this format:

a = [..., 800.0, 830.0, 900.0, 930.0, 1000.0, 1030.0, ...]

The problem is that leading zeroes for hours are missing. For example 00:30 is represented by 30, 08:00 is represented by 800. and 00:00 is represented by 2400.
Is it possible to parse this data to time object using strptime method?
I tried using following code

hours = [time.strptime(str(int(i)), "%H%M") for i in a]

but got

ValueError: unconverted data remains: 0

P.S. I’m using Python 2.7.

  • 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-18T11:25:43+00:00Added an answer on June 18, 2026 at 11:25 am

    Use zfill to add those zeros back as needed:

    hours = [time.strptime(i[:-1].zfill(4), "%H%M") for i in a]
    

    By using i[:-1] we remove that pesky trailing dot, and .zfill(4) will add enough 0 characters to the left to make it to 4 digits.

    Demo:

    >>> import time
    >>> a = ['800.', '830.', '900.', '30.']
    >>> [time.strptime(i[:-1].zfill(4), "%H%M") for i in a]
    [time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=8, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=1, tm_isdst=-1), time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=8, tm_min=30, tm_sec=0, tm_wday=0, tm_yday=1, tm_isdst=-1), time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=9, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=1, tm_isdst=-1), time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=30, tm_sec=0, tm_wday=0, tm_yday=1, tm_isdst=-1)]
    

    If they are float values instead, use the format() function on them to give you zero-padded values:

    >>> format(800., '04.0f')
    '0800'
    

    So do this:

    hours = [time.strptime(format(i % 2400, '04.0f'), "%H%M") for i in a]
    

    where % 2400 normalizes your values to the 0. to 2399. range.

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

Sidebar

Related Questions

I have this function which is supposed to set a certain time format to
I have a tool which requires the time in hex format. Suppose if date
How do I check for time for between. suppose I have Time in string
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a static method of my class that returns an object of
Suppose I have a class Baz that inherits from classes Foo and Bar ,
I have the data in the Sqlite DB in this format.. month year FarmerCode
suppose i have one column in mysql database which is stated last time one
Suppose I have a table like that: create table reserved ( id int(4) primary
I have this CalendarView below and if i click that day which is the

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.