def string2year(s):
"""
Converts from a string in the format DDMMYYYY to a python datetime tuple.
>>> string2year('28122014')
returns datetime.datetime(2014, 12, 22, 0, 0).
:param y: a string or list of strings
:returns: a datetime structure (or list) with the date corresponding to the input float or array
Reference: https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
"""
import datetime
if numpy.size(s)==1: # if input is a string
date=datetime.datetime.strptime(str(s),'%d%m%Y')
else: # if input is list/array
date=[]
for i, si in enumerate(s):
date.append(datetime.datetime.strptime(str(si),'%d%m%Y'))
return date
评论列表
文章目录