# 如何将帖子数据从相对数据改为绝对数据

**URL:** https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700
**Category:** Support
**Created:** [2025年五月12日 09:33 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700 "2025-05-12T09:33:09Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![aksoforever](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aksoforever/32/502615_2.png) [@aksoforever](https://meta.discourse.org/u/aksoforever)
#### Post date: [2025年五月12日 09:33 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/1 "2025-05-12T09:33:09Z")

</div>

大家好：  
我想将帖子数据格式修改为 YYYY-MM-DD HH:mm  
在前端 JavaScript 中修改似乎不合理  
1.我可以使用主题来覆盖这个时间吗？  
2.我该如何在电子邮件中修改（现在只显示日期）？

---

<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: [2025年五月12日 09:37 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/3 "2025-05-12T09:37:27Z")

</div>

所有日期格式以及其他文本均可自定义。请参阅此指南：

> [@Customize text in Discourse](https://meta.discourse.org/t/customize-text-in-discourse/36092):
>
> bookmark This is a guide for customizing text in Discourse via the admin interface, enabling changes to various UI elements. person_raising_hand Required user level: Administrator In Discourse, you can customize all of the text via the admin interface. This can be useful for tailoring the user experience to better fit the particular tone or branding of your community. Summary This guide will cover: Accessing the text customization interface Editing text strings Identifying translatio…

---

<div class="post-metadata">

### Author: ![aksoforever](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aksoforever/32/502615_2.png) [@aksoforever](https://meta.discourse.org/u/aksoforever)
#### Post date: [2025年五月12日 12:51 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/4 "2025-05-12T12:51:43Z")

</div>

谢谢你的回复，David  
我看到了这个自定义设置，但似乎在这里找不到。  
我想将所有帖子的时间格式显示为绝对时间。例如，当前我的主题帖子“3h”显示为“12 May 17:33”

 ![图片包含一个标有“Y-MM-DD HH:mm”的文本字段和一个蓝边框的框，框内有“3h”字样，旁边有一个笔形图标，表示持续时间或时间输入。(由AI配图)](https://global.discourse-cdn.com/meta/original/4X/b/a/f/baf5129c0cbadf5da3c4fdfcfc032e4d1a159bab.png)  
你知道有什么好方法可以将所有帖子数据更改为 YYYY-MM-DD HH:mm 格式，即使帖子发布了几分钟吗？

---

<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: [2025年五月12日 13:02 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/5 "2025-05-12T13:02:30Z")

</div>

哦，我明白了！

在那种情况下，你可以尝试更改“相对日期持续时间”网站设置。

> **relative\_date\_duration:** 发布后显示为相对日期（如7天）而非绝对日期（如2月20日）的天数。

所以我认为对于你的情况，你可以将其设置为 0

---

<div class="post-metadata">

### Author: ![aksoforever](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aksoforever/32/502615_2.png) [@aksoforever](https://meta.discourse.org/u/aksoforever)
#### Post date: [2025年五月12日 13:11 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/6 "2025-05-12T13:11:14Z")

</div>

是的，  
我已经将它设置为 0，但现在仍然不起作用。它需要一些时间还是我需要像更改域名后那样执行 `rake posts:rebake`？

---

<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: [2025年五月12日 13:15 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/7 "2025-05-12T13:15:14Z")

</div>

只需刷新页面即可生效。它是否带来了任何改变？现在你的发帖日期看起来怎样？

---

<div class="post-metadata">

### Author: ![aksoforever](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aksoforever/32/502615_2.png) [@aksoforever](https://meta.discourse.org/u/aksoforever)
#### Post date: [2025年五月12日 13:18 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/8 "2025-05-12T13:18:09Z")

</div>

我已刷新页面，但仍显示“36”

 ![The image shows a section of a blueprint or schematic with the heading "A Mini PCle Schematic" and a drawing instrument icon, accompanied by the measurement "36m". (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/e/0/1/e012ed42baad7b69542a045f3153625e09c81cf4.png)

并且设置是0

 ![The image shows a filter setting where post dates are displayed as relative time, specifying that new posts will be shown as "x days ago" instead of using absolute dates, with an example of using "7 days" instead of "20 Feb". (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/0/9/f/09f59e17a3a9d2a6f0c7eaece21f21dc24fef47f.png)

---

<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: [2025年五月12日 13:24 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/9 "2025-05-12T13:24:34Z")

</div>

嗯，看起来距离现在不到 23.5 小时的时间戳总是会显示为相对时间，无论该设置如何：

> <https://github.com/discourse/discourse/blob/5883085af3685972e334903669f1594fe35135c1/app/assets/javascripts/discourse/app/lib/formatter.js#L233C5-L247C13>

因此，您对该设置的更改将应用于超过 1 天的帖子。但似乎我们目前没有办法改变一天以内内容的显示行为。

---

<div class="post-metadata">

### Author: ![aksoforever](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aksoforever/32/502615_2.png) [@aksoforever](https://meta.discourse.org/u/aksoforever)
#### Post date: [2025年五月12日 13:39 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/10 "2025-05-12T13:39:58Z")

</div>

我看到了这个文件  
[discourse-main/app/assets/javascripts/discourse/app/components/post/meta-data/date.gjs](https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/components/post/meta-data/date.gjs)

```html
<template>
    <div class="post-info post-date">
      <a
        class={{concatClass
          "post-date"
          (if (and @post.wiki @post.last_wiki_edit) "last-wiki-edit")
        }}
        href={{@post.shareUrl}}
        title={{i18n "post.sr_date"}}
        {{on "click" this.showShareModal}}
      >
        <RelativeDate @date={{this.date}} />
      </a>
    </div>
  </template>

```

这是正确的模板吗，我可以通过主题组件来修改它吗？

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [2025年五月12日 19:33 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/12 "2025-05-12T19:33:53Z")

</div>

不，您无法覆盖 .gjs 模板，不幸的是（旨在提高和鼓励覆盖的稳定性）

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [2025年五月22日 00:39 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/13 "2025-05-22T00:39:27Z")

</div>

欢迎回来。@aksoforever！

你在处理这个问题时进展如何？能不能告诉我们更多关于你的用例？

为什么你会想对你的成员设置如此长的绝对日期？"多久以前"的日期在视觉上更友好，还能传达你需要知道一则帖子有多旧的信息。将鼠标悬停在上面会显示明确的时间戳。

---

<div class="post-metadata">

### Author: ![aksoforever](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aksoforever/32/502615_2.png) [@aksoforever](https://meta.discourse.org/u/aksoforever)
#### Post date: [2025年五月22日 01:24 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/14 "2025-05-22T01:24:59Z")

</div>

感谢您的关注 @tobiaseigen

是的，现在Discourse的显示非常现代和友好，更适合大多数人

只有少数经常使用它的人觉得使用绝对时间更快、更直接。

关于邮件中的时间，现在只显示月份和日份。  
使用电子邮件查看信息并不用户友好，尤其是在查看多年前的信息时，没有显示年份。

---

<div class="post-metadata">

### Author: ![aksoforever](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aksoforever/32/502615_2.png) [@aksoforever](https://meta.discourse.org/u/aksoforever)
#### Post date: [2025年五月22日 01:27 UTC](https://meta.discourse.org/t/how-to-change-the-post-data-from-relative-data-to-absolute/365700/15 "2025-05-22T01:27:48Z")

</div>

我目前正在使用降级版的Discourse，并用组件重写前端代码

电子邮件在插件中使用以下内容，我可以从主题组件修改short\_date吗？

```plaintext
after_initialize do
  if SiteSetting.custom_email_date_format_enabled
    module ::EmailHelper
      def short_date(datetime)
        china_time = datetime.in_time_zone("Asia/Shanghai")
        china_time.strftime("%Y-%m-%d %H:%M")
      end
    end
  end
end

```
