我在GMT-3上,但是由GitHub的用于Windows的Git捆绑的bash端口中的date命令没有看到这一点,而是选择UTC的时间,并认为这也是本地时间。

相比之下,这里有一个运行在GMT-4上的健康盒子:

我如何使我的脚本显示正确的时间,以一种甚至在MSysGit中跨平台工作的方式?
(相关:关于Cygwin类似问题的一个问题)
发布于 2014-07-02 18:39:01
无论您是在Windows还是Linux上运行它,这个函数都会给您正确的时间:
# Are we running on Windows?
isWindows() { [[ -n "$WINDIR" ]]; }
# Get time, cross-platform.
getTime() {
if isWindows; then
cmd.exe "/c echo %time%" | head -c 8 | tr ' ' 0 # pad single-digit hours.
else
date +%T
fi
}获取日期也将留作阅读练习(提示提示:%date%)。
https://stackoverflow.com/questions/24538632
复制相似问题