关于如何在CentOS 7中将日期时间从这种格式Thu Jun 4 20:30:43 WIB 2020更改为Thu Jun 4 20:33:43 +07 2020,我有一个愚蠢的问题。这可能吗?顺便说一句,我在安装CentOS 7时使用的是timedatectl。
# date
Thu Jun 4 20:36:46 WIB 2020
更改为
# date
Thu Jun 4 20:36:46 +07 2020
感谢您的帮助。
检查shell的当前语言环境:
locale
然后根据您的需要,从date_fmt
文件中编辑/usr/share/i18n/locales/$YOUR_LOCALE_HERE
变量。在这种情况下:
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)
这意味着上一个命令将返回以下内容:
Thu Jun 4 20:22:47 +02:00 2020
但是,您始终可以为您的alias
命令定义自定义date
,以根据需要准确显示:
alias date='date "+%a %b %e %H:%M:%S %:z %Y" |sed "s|:00||"'
将其添加到您的.bashrc
文件中或将别名存储到任何地方,都应该没事。