문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top