我想从 url 获取 json 响应,并在 windows 命令提示符下使用 curl 将其保存到 .json 文件中。
我的目标是为文件名添加时间戳。
以下不起作用。
curl -k --ntlm -u : --write-out '%{json}' https://myurl.com -o "myfile$(date +\"%H:%M\").json"
以下工作正常并产生预期的输出,但没有时间戳。
curl -k --ntlm -u : --write-out '%{json}' https://myurl.com -o "myfile.json"
如何获取带有时间戳的 .json
文件?
我在这里尝试了这两个建议,但似乎没有任何效果。 enter link description here
答案 0 :(得分:1)
这应该有效:
curl -k --ntlm -u : --write-out '%{json}' https://myurl.com -o "myfile%TIME:~0,2%-%TIME:~3,2%.json"
%TIME%
是 Windows 内置的动态环境变量,~0,2
和 ~3,2
需要从中提取小时和分钟子字符串。
请注意,Windows 中的文件名中不允许使用冒号,因此我将其替换为破折号。