Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Curl命令输出带有时间戳的文件名_Curl_Cmd - Fatal编程技术网

Curl命令输出带有时间戳的文件名

Curl命令输出带有时间戳的文件名,curl,cmd,Curl,Cmd,我想从url获取json响应,并使用windows命令提示符中的curl将其保存到.json文件中 我的目标是为文件名添加时间戳 以下方法不起作用 curl -k --ntlm -u : --write-out '%{json}' https://myurl.com -o "myfile$(date +\"%H:%M\").json" 它会生成这样一个没有内容的文件。 下面的代码工作正常,并生成预期的输出,但没有时间戳 curl -k --ntlm -

我想从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
文件

我在这里尝试了这两种建议,但似乎没有任何效果。

这应该可以:

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中,文件名中不允许使用冒号,因此我用破折号替换了冒号。

效果很好!非常感谢@RenatPlease注意,使用
%TIME%
取决于最终用户指定的配置,因此
%TIME:~0,2%-%TIME:~3,2%
只适用于部分最终用户,而不是所有用户,如果不需要空间,可能大多数用户都不需要。