首页 > 解决方案 > 在同一命令中从 json 时间读取的 UTC 时间更改为 UTC+1

问题描述

我用这个命令做一个卷曲:

卷曲“ https://api.sunrise-sunset.org/json?lat=46.745995&lng=7.122781&date=today ” | jq '.results.sunrise'

结果是:

“上午 5 点 31 分 51 秒”

我住在 UTC+1,我需要在同一个命令中增加一小时。

如果命令不起作用,您需要使用 apt install jq 安装 jq 或为 Windows 下载它

标签: jsoncurljq

解决方案


一种选择是使用 jq 的这种调用:

jq '.results.sunrise
| strptime("%I:%M:%S %p")
| {h: ((.[3] + 1) % 24), m:.[4], s:.[5]}
| if .h < 12 then "\(.h):\(.m):\(.s) AM"
  elif .h == 12 then "\(.h):\(.m):\(.s) PM"
  else "\(.h - 12):\(.m):\(.s) PM"
  end '

推荐阅读