【问题标题】:What is difference between javascript and python time stamp?javascript和python时间戳有什么区别?
【发布时间】:2014-10-31 17:33:45
【问题描述】:

我有这个 javascript 代码:

(new Date()).getTime()

还有这个python代码:

time.time()

第一个返回类似 1410072754803 的东西,但 python 返回类似 1410077369.27 的东西,我需要 python 返回与 javascript 相同的格式。我怎样才能得到它?

PS:如果我使用

time.time() * 1000

它返回:

1.41007799536e+12

【问题讨论】:

  • 将 python 乘以 1000 并将其转换为整数。
  • 另一个答案上的 cmets 回答了您的更新; time.time() 是一个浮点值,将其四舍五入转为整数:int(round(time.time() * 1000))
  • @MartijnPieters:你确定在 Python 中 javascript epoch 总是等于 time.gmtime(0) -- 无论两种语言都运行在什么系统上?
  • @J.F.Sebastian:我不知道。
  • @MartijnPieters:那么问题不是重复的(理论上)

标签: javascript python time


【解决方案1】:

一个返回毫秒,而另一个返回浮点数。

Python 相当于 javascript 时间戳。

jts = int(time.time()*1000)

【讨论】:

    猜你喜欢
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 2014-05-13
    • 2015-11-11
    • 2011-06-28
    相关资源
    最近更新 更多