在 CentOS 7 中更改时区显示

Change timezone display in CentOS 7

我有一个愚蠢的问题,关于如何将 CentOS 7 中的日期时间从这种格式 Thu Jun 4 20:30:43 WIB 2020 更改为 2020 年 6 月 4 日星期四 20:33:43 +07。这可能吗?顺便说一句,我在安装CentOS 7时使用的是timedatectl。

# date
Thu Jun  4 20:36:46 WIB 2020

改为

# date
Thu Jun  4 20:36:46 +07 2020

感谢任何帮助。

检查您的 shell 当前区域设置:

locale

然后根据您的文件编辑 /usr/share/i18n/locales/$YOUR_LOCALE_HERE 文件中的 date_fmt 变量。在这种情况下:

date_fmt "+%a %b %e %H:%M:%S %:z %Y"

并在更改后再次重建您的本地化文件:

locale-gen

date man page 中所示,默认情况下似乎仅支持以下时区格式:

       %z     +hhmm numeric time zone (e.g., -0400)

       %:z    +hh:mm numeric time zone (e.g., -04:00)

       %::z   +hh:mm:ss numeric time zone (e.g., -04:00:00)

       %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)

       %Z     alphabetic time zone abbreviation (e.g., EDT)

这意味着前面的命令将return以下内容:

Thu Jun  4 20:22:47 +02:00 2020

但是,您始终可以为 date 命令定义自定义 alias 以准确显示您想要的内容:

alias date='date "+%a %b %e %H:%M:%S %:z %Y" |sed "s|:00||"'

将它添加到您的 .bashrc 文件或您存储别名的任何地方,您应该没问题。