Getting timestamp from mongodb id

前端 未结 8 1775
误落风尘
误落风尘 2020-12-02 08:38

How do I get the timestamp from the MongoDB id?

8条回答
  •  误落风尘
    2020-12-02 09:08

    In the server side make _id of MongoDB ObjectId

    date = new Date( parseInt( _id.toString().substring(0,8), 16 ) * 1000 )

    And on the client side use

    var dateFromObjectId = function (objectId) {
    return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
    };
    

提交回复
热议问题