I have written a function in python that accepts a timestamp and returns the timestamp with respect to the current timezone.
Code
def datetime_from_utc_to_local(utc_datetime):
now_timestamp = time.time()
offset = datetime.fromtimestamp(now_timestamp) - datetime.utcfromtimestamp(now_timestamp)
return utc_datetime + offset
Error:
unsupported operand type(s) for +: 'int' and 'datetime.timedelta'
Can you please help me fix this error.
I want this function to return the timestamp
offset
is a datetime.timedelta
object. If you need just the seconds, extract them with timedelta.total_seconds()
:
return utc_datetime + offset.total_seconds()
Your function signature however, suggests it was expecting you to feed it a datetime.datetime()
object, in which case you shouldn't change this function, but the code that calls it. Clearly you are giving it an integer instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With