如何将MongoDB ID转换为各自的日期? (我对使用getTimestamp()
...)
答案 0 :(得分:1)
如果你没有在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"
为了我未来的自我...