python - Python datetime 到 Unix 纪元时间戳
问题描述
我正在尝试将 pandas 日期时间对象转换为 unix/epoch 时间戳。我收到数据集中某个特定日期的错误。
我正在尝试的时间戳是这些:
1) 2019-08-31 21:38:00
2) 2019-01-09 16:26:00
我正在使用 Python 的 datetime 模块:
1) datetime.strptime('2019-08-31 21:38:00', '%Y-%m-%d %H:%M:%S').timestamp()
1567280280.0
2) datetime.strptime('2019-01-09 16:26:00', '%Y-%m-%d %H:%M:%S').timestamp()
1547047560.0
尽管对象 (2) 大于 (1),但 python 中的纪元时间戳显示不同。
当我在 excel 中将相同的日期时间对象转换为数值时,我得到:
1) '2019-08-31 21:38:00' -> 43708.901389
2) '2019-01-09 16:26:00' -> 43709.684722
哪个是对的。对象 (2) > 对象 (1)。
显然日期 (1) 小于日期 (2)。
为什么它使用python显示错误的顺序?
解决方案
推荐阅读
- xamarin.forms - 无法在 Xamarin.Forms 中启动 Whatsapp
- ios - 如何在 obj c 中的 avplayer 视频上添加叠加层?
- regex - 正则表达式:匹配 url 但不匹配电子邮件域
- react-native - React-native 与 native-base:数据更改未反映
- wordpress - 正文没有结束标签。好吗?
- gcc - GNU 标准库命名约定
- java - 如何将我的回复与新员工进行比较?
- android - 谷歌浏览器在安卓上强制停止后继续工作
- javascript - NodeJS 找不到模块 'grpc'
- elasticsearch - 为多值字段搜索获得正确的相关性