I'm using Python 3.7 and Django. I wanted to get the number of seconds (or milliseconds) since 1/1/1970 for a datetime object. Following the advice here -- In Python, how do you convert a `datetime` object to seconds?, I implemented
now = datetime.now()
...
return [len(removed_elts) == 0, score, now.total_seconds()]
but the "now.total_seconds()" line is giving the error
AttributeError: 'datetime.datetime' object has no attribute 'total_seconds'
What's the right way to get the seconds since 1/1/1970?
datetime
objects to get atimedelta
object (which does have an attributetotal_seconds
). I believe that this answer on the question you linked does what you want. But you can also usedatetime.timestamp
as mentioned below. – Storebought