2

I have made a small program for my weather station in python and its all working perfectly, but I have one little problem.

The output displays as

2014/5/18 04:03:41
2014/5/18 19:47:41

I want it to display as

04:03:41
19:47:41

Is there any easy way to do this,I was thinking of just stripping the characters out but it sounds more of a bodge than converting.

Thanks for any help

hexce
  • 151
  • 1
  • 1
  • 12

1 Answers1

4
In [66]: t="2014/5/18 19:47:41".split()

In [67]: print t[-1]
19:47:41

If you have a string just split and get the last element which is the time.

t="2014/5/18 04:03:41"
from datetime import datetime
str_time= datetime.strptime(t,'2014/5/18  %H:%M:%S').time()
In [72]: print str_time
04:03:41

datetime docs

Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321