bibi45

2020-08-06 | Backend 中文

DRF 日期格式化:展示格式不能改变时间语义

bibi45

API 输出可以友好,但存储、时区和输入格式必须保持明确。

This article is currently available in Chinese. The language switch changes the site interface; the original text is shown below.

DateTimeField(format=...) 可以改变输出展示,但不要因此丢失时区或把日期字符串当作排序依据。

对跨系统 API,优先使用带时区的 ISO 8601 时间。需要面向用户展示时,让前端按用户 locale 渲染;后端保存 UTC,并在测试中覆盖夏令时和空值场景。

© 2026 bibi45. All rights reserved.

Built as a static, Git-owned site.