【发布时间】:2018-11-20 22:17:51
【问题描述】:
当使用auto_now_add在Django的DateTimeField中保存时间戳时:
creation_timestamp = models.DateTimeField(auto_now_add=True)
字段以毫秒为单位保存:
2018-11-20T15:58:44.767594-06:00
我想将其格式化为无毫秒显示:
2018-11-20T15:58:44-06:00
但我能想到的唯一选择并不能完全显示我需要什么:
format="%Y.%m.%dT%H:%M:%S%z" 给我2018.11.20T15:58:44-0600
如何按我需要的方式格式化此字段?
或者,我宁愿在没有毫秒的情况下保存 DateTimeField,但 auto_now_add 允许做这种事情吗?
【问题讨论】:
标签: python django django-models