【问题标题】:Python 3.6.X: Different values of from timestamp on Windows and LinuxPython 3.6.X:Windows 和 Linux 上 from timestamp 的不同值
【发布时间】:2019-06-17 20:09:16
【问题描述】:

以下脚本在 Windows 和 Linux 操作系统上给出不同的输出。

import datetime
datetime.datetime(2013, 12, 10, 12, 57, 4).timestamp()

以下是依赖于操作系统的输出

  • 在 Windows 上,1386660424.0
  • 在 Linux 上,1386680224.0

我很想知道为什么会有差异?

【问题讨论】:

  • 你的windows结果看起来很差,即使UTC,时间也不会匹配。
  • @l'L'l 感谢您的回复先生,实际上时差与本地时区和UTC之间的时差完全相同,即330分钟。
  • 你住在哪里?我从来没有听说过这样的事。如果我在这里并且它在其他地方是12:57,它可能是5:577:57 等,虽然我不认为这里可能是12:57 而它在其他地方是5:27
  • 印度。因为IST(UTC +5:30) 所以有330 min.的差异。

标签: python python-3.x timestamp


【解决方案1】:

解决了!
如果您看到时差是seconds = 19800minutes=330hrs=5:30
两台机器可以有不同的时区设置。
使用 UTC 时区比较时间戳。
例如。

from datetime import datetime, timezone
datetime(2013, 12, 10, 12, 57, 4, 0, timezone.utc).timestamp()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 2012-03-24
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    相关资源
    最近更新 更多