如何在bash中将时间戳转换为不同的时区?

如何在bash中将时间戳转换为不同的时区?,bash,date,Bash,Date,我有一个格林尼治标准时间,看起来是这样的: Wed Feb 13 04:46:54 +0000 2019 Tue Feb 12 22:46:54 CST 2019 postYear=`TZ="${timeZone}" date -jf "%Y-%m-%d %H:%M:%S %z" "${postYear}-${postMonth}-${postDay} ${postHourGmt}:${postMinute}:${postSecond} +0000" +%Y` 在MacOS 10.14.3

我有一个格林尼治标准时间,看起来是这样的:

Wed Feb 13 04:46:54 +0000 2019
Tue Feb 12 22:46:54 CST 2019
postYear=`TZ="${timeZone}" date -jf "%Y-%m-%d %H:%M:%S %z" "${postYear}-${postMonth}-${postDay} ${postHourGmt}:${postMinute}:${postSecond} +0000" +%Y`
在MacOS 10.14.3上的bash脚本中,我想将其转换为用户的本地时区。i、 例如,这一个是
04
,因此将其更改为我的时区将是
-6
,因此它将以如下方式结束:

Wed Feb 13 04:46:54 +0000 2019
Tue Feb 12 22:46:54 CST 2019
postYear=`TZ="${timeZone}" date -jf "%Y-%m-%d %H:%M:%S %z" "${postYear}-${postMonth}-${postDay} ${postHourGmt}:${postMinute}:${postSecond} +0000" +%Y`

提前谢谢。

这就是你要找的吗

 date -d "Wed Feb 13 04:46:54 +0000 2019 - 6 hour"


最后我用了这样的东西:

Wed Feb 13 04:46:54 +0000 2019
Tue Feb 12 22:46:54 CST 2019
postYear=`TZ="${timeZone}" date -jf "%Y-%m-%d %H:%M:%S %z" "${postYear}-${postMonth}-${postDay} ${postHourGmt}:${postMinute}:${postSecond} +0000" +%Y`
…变量为我想从中提取的日期提供输入


…而这一年(%Y)是我要抽出的。

Emma,(前两个链接是相同的…?)这些链接看起来像是用于当前时间的。这是文件的时间戳,而不是当前时间。这两种方法都不适用于mac os bash:Susans iMac:dotw kitykity$date-d“$dt$tz hour”用法:date[-jnRu][-d dst][-r seconds][-t west][v[+|-]val[ymwdHMS]]。。。[-f fmt日期|[[mm]dd]HH]mm[[cc]yy][.ss][+格式]