Difference between evaluating timestamp and total_seconds

后端 未结 3 2022
感情败类
感情败类 2021-01-07 00:52

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

3条回答
  •  时光取名叫无心
    2021-01-07 01:42

    .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)

提交回复
热议问题