、在实体类中添加了一个字段来存储当前时间戳用于计算实体创建后的持续时间。```python
class Entity:
def __init__(self, name, created_at=None):
self.name = name
self.created_at = created_at or datetime.now()
def get_duration(self):
if self.created_at is None:
return None
return (datetime.now() - self.created_at).total_seconds()
```
大家还看了:
饮什么茶去湿气
编辑:普洱茶-合作伙伴
本文链接:http://www.guanxian.org/consult/chapin/18406000760.html