【问题标题】:Timestamp from Node is 3 minutes behind when converted to Python datetime转换为 Python 日期时间时,来自 Node 的时间戳落后 3 分钟
【发布时间】:2015-03-29 21:31:50
【问题描述】:

我有一个在 Mongoose 模型上设置时间戳的 Node/Express API:

var NotificationSchema = new Schema({
    created_on: {
        type: Number,
        default: new Date().getTime()
    },
    . . .
});

当我在 Django 中将其转换为 Python 日期时间时:

created_on = datetime.fromtimestamp(notification['created_on'] / 1000.0)

正好晚了 3 分钟。两个应用程序都在同一台服务器上运行。这个时间戳是怎么回事?

【问题讨论】:

    标签: javascript python django datetime python-3.x


    【解决方案1】:

    想通了。就像指定默认值一样简单:

    var NotificationSchema = new Schema({
        created_on: {
            type: Number,
            default: Date.now
        },
        . . .
    });
    

    现在每次保存模型时,都会正确调用 Date.now。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-15
      • 2019-02-03
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多