在Linux Shell中获取CST日期
我试图在Linux中以CST格式获得当前日期。
todaysDate=$(date +%Y-%m-%d-%H:%M:%S);
echo 'todaysDate: '${todaysDate};
结果:todaysdate:2022-06-03-09:15:42
正在给我UTC的时间。在不更改系统时间设置的情况下,如何获得CST的时间?
提前致谢
I am trying to get the current date in CST format in linux.
todaysDate=$(date +%Y-%m-%d-%H:%M:%S);
echo 'todaysDate: '${todaysDate};
Result: todaysDate: 2022-06-03-09:15:42
is giving me time in UTC. How can I get the time in CST instead, without changing the system time settings?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参见这个答案在UNIX堆栈交换上。您基本上预处了一个仅适用于您要发行的命令有效的环境变量:
所有可用时区都在
/usr/usr/share/Zoneinfo
中列出。See this answer on the Unix stack exchange. You basically prepend an environment variable that is only valid for the very command you're trying to issue:
All available timezones are listed in
/usr/share/zoneinfo
.将环境变量
TZ
设置为CST6CDT
。Set the environment variable
TZ
toCST6CDT
.