Pregunta

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.

¿Fue útil?

Solución

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

Otros consejos

Convert to strings, split and print out would work:

for number in a:
    str_number = str(number)
    print('{}:{}:{}'. format(str_number[:2], str_number[2:4], str_number[4:]))


12:10:11
12:10:20
12:10:25
12:10:30
12:10:32
12:10:37
12:12:34
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top