You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求指导TimeAPI的URL参数拼接及PowerShell curl正确语法

TimeAPI增量计算接口的正确URL参数格式

timeapi.io的增量计算接口(/api/Time/add)采用查询字符串传递参数,核心参数规则如下:

  • date:必填,基准时间,格式需为ISO 8601(如2024-05-20T14:30:00或仅日期2024-05-20)
  • 增量参数:可选,支持years/months/days/hours/minutes/seconds,值为整数(正数表示向后累加,负数表示向前递减)

完整URL示例:

https://timeapi.io/api/Time/add?date=2024-05-20T14:30:00&years=1&months=3&days=5

该URL用于计算2024年5月20日14:30往后1年3个月5天的时间结果。

Windows PowerShell中的curl调用语法

注意:PowerShell里的curl是Invoke-WebRequest的别名,调用时需注意参数解析规则,推荐两种实用写法:

写法1:直接拼接完整URL调用

curl "https://timeapi.io/api/Time/add?date=2024-05-20T14:30:00&years=1&months=3&days=5"

如需将返回结果转为易读的JSON格式,可追加管道命令:

curl "https://timeapi.io/api/Time/add?date=2024-05-20T14:30:00&years=1&months=3&days=5" | ConvertFrom-Json

写法2:用-Uri和-Body传递参数(更易维护)

这种方式无需手动拼接URL,PowerShell会自动处理参数编码,需指定-Method Get避免默认POST请求导致失败:

Invoke-WebRequest -Uri "https://timeapi.io/api/Time/add" -Body @{
    date = "2024-05-20T14:30:00"
    years = 1
    months = 3
    days = 5
} -Method Get | ConvertFrom-Json

内容的提问来源于stack exchange,提问作者Miguel Etchepare

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 21:34:52