What is the fastest way to trim datetime object of this form 2016-12-14 15:57:16.140645
to become like this: 2016-12-14 15:57:16
? doing str('2016-12-14 15:57:16.140645').strip(".")[0]
is painfully slow for large datasets and besides I need the returned format to be a datetime object
For those that came here for the actual question 'Remove timezone information from datetime object', the answer would be something like:
datetimeObject.replace(tzinfo=None)
from datetime import datetime, timezone
import time
datetimeObject = datetime.fromtimestamp(time.time(), timezone.utc)
print(datetimeObject)
datetimeObject = datetimeObject.replace(tzinfo=None)
print(datetimeObject)
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