-2

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.

martineau
  • 119,623
  • 25
  • 170
  • 301
Jay
  • 291
  • 1
  • 6
  • 19

2 Answers2

3

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
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
1

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
Mike Müller
  • 82,630
  • 20
  • 166
  • 161