When I evaluate the number of seconds between two dates using two different methods (either using timestamp() or total_seconds()) in datetime in python, I get different resu
.timestamp only works in Python 3 (New in version 3.3). There is no such method in Python 2.
Changed in version 3.6: The timestamp() method uses the fold attribute to disambiguate the times during a repeated interval.
Note: There is no method to obtain the POSIX timestamp directly from a naive datetime instance representing UTC time. If your application uses this convention and your system timezone is not set to UTC, you can obtain the POSIX timestamp by supplying tzinfo=timezone.utc:
timestamp = dt.replace(tzinfo=timezone.utc).timestamp()
or by calculating the timestamp directly:timestamp = (dt - datetime(1970, 1, 1)) / timedelta(seconds=1)