Search code examples
pythontimenp

Python time from a 6 digit number


I have a series of six digit numbers in this array:

a = np.array((121011,121020,121025,121030,121032,121037,121234))

How do I get a time from each of the six digit numbers? e.g.:

12:10:11

I wish to use the time for calculations.


Solution

  • Since you said you wanted to do calculations, you probably want time objects, not strings.
    See the documentation.

    for number in a:
        h = number // 10000
        m = (number // 100) - (h * 100)
        s = number % 100
        t = time(h,m,s)
        # then do whatever you want with t