# UI 中 post.created\_at 日期与数据库不匹配

**URL:** <https://meta.discourse.org/t/ui-post-created-at-date-doesnt-match-db/150717>\
**Category:** Bug\
**Created:** [2020年五月7日 13:18 UTC](https://meta.discourse.org/t/ui-post-created-at-date-doesnt-match-db/150717 "2020-05-07T13:18:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grayden\_Shand](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grayden_shand/32/166586_2.png) [@Grayden\_Shand](https://meta.discourse.org/u/Grayden_Shand)\
**Post date:** [2020年五月7日 13:18 UTC](https://meta.discourse.org/t/ui-post-created-at-date-doesnt-match-db/150717/1 "2020-05-07T13:18:21Z")

</div>

在用户的动态消息中，会显示帖子发布的日期：  
[![](https://global.discourse-cdn.com/meta/original/3X/9/d/9ddb15553fc11d38dfd2c111cf2c65f8db8c0227.png) ](https://dl.dropboxusercontent.com/s/imioybgfdb2c62c/Screenshot%202020-05-07%2009.12.26.png?dl=0)

然而，当我使用数据探索器插件查看此帖子时，发现它创建于 4 月 21 日，而非 4 月 20 日。

[![](https://global.discourse-cdn.com/meta/original/3X/3/6/362a58f96e37f956a411417fbaafda0616577ca5.png) ](https://dl.dropboxusercontent.com/s/zivs3yx182vzzhw/Screenshot%202020-05-07%2009.14.16.png?dl=0)

因此，在数据库中，该帖子创建于 4 月 21 日，但用户界面却显示为 4 月 20 日发布。

**这为何重要？**  
我们有一个自定义功能用于追踪连续访问天数。偶尔会有用户联系询问为何他们的连续记录中断。在这种情况下，中断的原因是：在数据库中，该用户在 4 月 20 日没有任何活动记录，但从他们的角度来看，他们看到自己当天发布了帖子。

有人知道为何用户界面和数据库中的日期会不一致吗？

---

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [2020年五月7日 13:19 UTC](https://meta.discourse.org/t/ui-post-created-at-date-doesnt-match-db/150717/2 "2020-05-07T13:19:21Z")

</div>

数据库时间戳采用 UTC 格式（末尾的 Z 代表 [“祖鲁时间”](https://www.timeanddate.com/time/zones/z)）。用户界面时间戳将显示为浏览器所在的本地时区时间。这是否能解释该差异？

---

<div class="post-metadata">

**Author:** ![Grayden\_Shand](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grayden_shand/32/166586_2.png) [@Grayden\_Shand](https://meta.discourse.org/u/Grayden_Shand)\
**Post date:** [2020年五月7日 13:23 UTC](https://meta.discourse.org/t/ui-post-created-at-date-doesnt-match-db/150717/3 "2020-05-07T13:23:25Z")

</div>

啊，明白了。没错，情况确实如此。帖子发布时是 UTC 午夜，但在我的浏览器（EST）上显示为减去 4 小时，所以日期变成了 4 月 20 日。

虚惊一场，抱歉！

感谢你的帮助 @david

---

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [2020年五月7日 13:59 UTC](https://meta.discourse.org/t/ui-post-created-at-date-doesnt-match-db/150717/4 "2020-05-07T13:59:18Z")

</div>


