TimeFormatter
一款简单的客户端 Minecraft 模组,可自动查找并格式化聊天中的 Discord 风格时间戳,将其转换为你本地的时间。
功能
- 仅客户端:无需在服务器端安装。在你加入的任何服务器上均可使用。只有安装了该模组的玩家才能看到格式化后的时间。
- 自动格式化:检测聊天消息中的时间戳,如
<t:1672531200>。
- 字面发送(非时区感知):如果聊天中发送了类似
<<t:1672531200>> 的时间戳,它将被替换为匹配的字面值(假设其长度不会超过 256 个字符的限制),从而对所有人可见。
- 本地时间转换:所有时间戳都会转换并显示在你的计算机本地时区中。
- 多种格式:支持 Discord 的所有标准时间戳格式化样式。
- 相对时间:可以以相对方式显示时间,例如“5 分钟前”或“2 小时后”。
工作原理
模组会检查传入的聊天消息中是否包含类似 <t:TIMESTAMP:STYLE>(或 <<t:TIMESTAMP:STYLE>>)的时间戳。
TIMESTAMP:Unix 时间戳(秒)。你也可以使用特殊值 yesterday、now 和 tomorrow 来分别代表昨天、现在和明天。
STYLE:一个可选的单字符,用于控制输出格式。如果你不提供样式,则默认为 f(短日期/时间)。
支持的样式
| 样式 |
示例输出 |
描述 |
t |
14:30 |
短时间 |
T |
14:30:00 |
长时间 |
d |
2023/12/31 |
短日期 |
D |
2023年12月31日 |
长日期 |
f |
2023年12月31日 14:30 |
短日期/时间 (默认) |
F |
2023年12月31日 星期日 14:30 |
长日期/时间 |
R |
5 分钟前 |
相对时间 |
示例
如果另一位玩家(假设处于 UTC 时区)在聊天中发送以下消息:
The server event will start at <t:1704067200:F>.
而你处于 GMT+1 时区,你将看到:
服务器活动将于 2024年1月1日 星期一 01:00 开始。
然而,如果 UTC 时区的玩家在聊天中发送此消息:
My date and time is <<t:1704067200:F>>.
所有人(即使没有安装此模组的玩家)都将看到:
我的日期和时间是 2024年1月1日 星期一 01:00。
安装
这是一个 Fabric 模组,需要 Fabric API。
- 下载最新版本。
- 将下载的
.jar 文件放入你的 .minecraft/mods 文件夹中。
- 使用 Fabric Loader 启动游戏。
从源码构建
- 克隆仓库:
git clone https://github.com/m3z0id/TimeFormatter.git
- 进入项目目录:
cd TimeFormatter
- 使用 Gradle 构建项目:
./gradlew build -Pmc=<Minecraft Version> -Pyarn=<Yarn Version> -Papi=<Fabric API Version> -Padventure=<Koryo Adventure Fabric Version>
- 编译后的
.jar 文件将位于 build/libs/ 目录中。
许可证
本项目采用 MIT 许可证授权。有关更多详细信息,请参阅 LICENSE 文件。
TimeFormatter
A simple client-side Minecraft mod that automatically finds and formats Discord-style timestamps in chat, converting them to your local time.
Features
- Client-Side Only: No server-side installation is required. It works on any server you join. The formatting works only with the mod installed.
- Automatic Formatting: Detects timestamps like
<t:1672531200> in chat messages.
- Literal Sending (not timezone aware): If a timestamp like
<<t:1672531200>> is sent in the chat, it will get replaced by a matching literal assuming it won't overflow the 256 character limit, thus visible to everyone.
- Local Time Conversion: All timestamps are converted and displayed in your computer's local time zone.
- Multiple Formats: Supports all of Discord's standard timestamp formatting styles.
- Relative Time: Can display time relatively, such as "5 minutes ago" or "in 2 hours".
How It Works
The mod checks incoming chat messages for timestamps like <t:TIMESTAMP:STYLE> (or <<t:TIMESTAMP:STYLE>>).
TIMESTAMP: A Unix timestamp (in seconds). You can also use the special values yesterday, now and tomorrow to represent the respective time.
STYLE: An optional single character that controls the output format. If you don't provide a style, it defaults to f (Short Date/Time).
Supported Styles
| Style |
Example Output |
Description |
t |
14:30 |
Short Time |
T |
14:30:00 |
Long Time |
d |
31/12/2023 |
Short Date |
D |
December 31, 2023 |
Long Date |
f |
December 31, 2023 at 14:30 |
Short Date/Time (Default) |
F |
Sunday, December 31, 2023 at 14:30 |
Long Date/Time |
R |
5 minutes ago |
Relative Time |
Example
If another player let's say in the UTC timezone sends the following message in chat:
The server event will start at <t:1704067200:F>.
And you're in the GMT+1 timezone, you'll see:
The server event will start at Monday, January 1, 2024 at 01:00.
However, if the player in UTC sends this message in chat:
My date and time is <<t:1704067200:F>>.
Everyone (even players without this mod) will see this:
The server event will start at Monday, January 1, 2024 at 01:00.
Installation
This is a Fabric mod and requires the Fabric API.
- Download the latest version.
- Place the downloaded
.jar file into your .minecraft/mods folder.
- Launch the game using the Fabric Loader.
Building from Source
- Clone the repository:
git clone https://github.com/m3z0id/TimeFormatter.git
- Navigate into the project directory:
cd TimeFormatter
- Build the project using Gradle:
./gradlew build -Pmc=<Minecraft Version> -Pyarn=<Yarn Version> -Papi=<Fabric API Version> -Padventure=<Koryo Adventure Fabric Version>
- The compiled
.jar file will be located in the build/libs/ directory.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
评论 0
登录后参与评分
还没有评论,来抢沙发吧