3

I have time given in the following format.

'August 28, 2017 Mon  03:30 am -  04:00 am'

I would like to convert it to the following utc format using arrow.

time =[u'2017-08-28T03:30:00+00:00', u'2017-08-28T04:00:00+00:00']

I was able to do it with very complex string manipulation but I think there is a smart way to do it using arrow.

krisfremen
  • 177
  • 1
  • 2
  • 13
Parshuram Thorat
  • 101
  • 1
  • 2
  • 13

1 Answers1

3

One of my friends was able quickly put it together and sent me this. Thought it might help others.

import arrow
from dateutil.parser import * 
t = 'Fri October 20 05:15 pm - 06:15 pm'
q = t.split('-')[0].strip()
x = t.split(' ')
x = ' '.join(x[:3]) +' '+ x[-2] + ' '+  x[-1]

arrow.get(parse(q)), arrow.get(parse(x))
Parshuram Thorat
  • 101
  • 1
  • 2
  • 13
  • 1
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. A ***good answer*** will always have an explanation of what was done and why it was done in such a manner, not only for the OP but for future visitors to SO. – Jay Blanchard Dec 07 '17 at 20:14
  • @JayBlanchard Thanks a lot for the advice Jay! I will make sure I will follow these in future. – Parshuram Thorat Dec 09 '17 at 15:54