I have this code into a class that get a string, my goal is parse the string , do some adjusts to get a valid datetime format from the string.
An input string for this function could be = "A0X031716506774"
import datetime
def _eventdatetime(self, string):
base_date = datetime.datetime.strptime("1980-1-6 0:0", "%Y-%m-%d %H:%M")
weeks = datetime.timedelta(weeks = int(string[5:9]))
days = datetime.timedelta(days = int(string[9]))
seconds = datetime.timedelta(seconds = int(string[10:15]))
stamp = base_date + weeks + days + seconds
adjustUTC = datetime.timedelta(hours = 3)
stamp = stamp - adjustUTC
return str(stamp)
Total time: 0.0483931 s, how can I improve the perfomance for this? The third line seems to be the slowest...
Thanks in advance...