I am currently using the below code to convert the format from two formats and it take lots of time, looking for some library that can identify the date without explicitly mentioning the formats. For eg I have values like " 2018-05-19 06:15:00.579", "2018-19-05 06:15:00.579", "1526723623892000000", etc in my DataFrame.
def time_formatter(val):
l=(len(str(val)))
if l==19:
formatted_date=datetime.utcfromtimestamp(int(val)/1000000000).strftime('%Y-%m-%d %H:%M:%S.%f')
elif l==23:
formatted_date=datetime.strptime(val, '%Y-%m-%d %H:%M:%S.%f')
elif l==3:
formatted_date=np.nan
else:
print(val)
raise ValueError
return formatted_date