如何将MongoDB ID转换为各自的日期? (我对使用getTimestamp()
的Javascript技术不感兴趣...)
如果您没有在MongoMapper或Mongoid中使用timestamps!
,您仍然可以从ObjectID本身获取created_at日期:
user = User.last
user.id
# => BSON::ObjectId('5a90731ddcd2d5008c000443')
user.id.generation_time.strftime('%Y-%m-%d %H:%M')
# => "2018-02-23 20:01"
为了我未来的自我......