【问题标题】:UTC time readed from a json time change to UTC+1 in the same command在同一命令中从 json 时间读取的 UTC 时间更改为 UTC+1
【发布时间】:2019-03-21 11:44:50
【问题描述】:

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

curl "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 下载它

【问题讨论】:

  • 我需要命令的结果是:“6:31:51 AM”

标签: json curl jq


【解决方案1】:

一种选择是使用 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 '

【讨论】:

  • 这正是我想要的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-23
  • 2016-10-11
  • 2014-11-18
  • 2012-03-20
  • 1970-01-01
  • 1970-01-01
  • 2010-12-01
相关资源
最近更新 更多