如何使用批处理文件将当前日期添加到html文件

时间:2014-01-21 13:54:59

标签: html batch-file

我有一个带有一些数据的html文件,那里有一行:

<span style='font-family:"Arial","sans-serif"'><span style='color:gray'>&nbsp;January 1, 2013</span></span>

有没有办法使用批处理文件将日期替换为当前日期?

1 个答案:

答案 0 :(得分:0)

将其另存为bat

 @if (@x)==(@y) @end /***** jscript comment ******
 @echo off
 for /f "delims=" %%d in ('cscript //E:JScript //nologo "%~f0"') do set "c_date=%%d"
 echo ^<span style='font-family:"Arial","sans-serif"'^>^<span style='color:gray'^>^&nbsp;%c_date%^</span^>^</span^>
 exit /b 0
 *****  end comment *********/

 var monthNames = [ "January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December" ];
 var now = new Date();
 var formated=  monthNames[now.getMonth()] + " " + now.getDay() +", "+ now.getFullYear();
 WScript.Echo(formated);

修改

 @if (@x)==(@y) @end /***** jscript comment ******
 @echo off
 for /f "delims=" %%d in ('cscript //E:JScript //nologo "%~f0"') do set "c_date=%%d"
 echo ^<span style='font-family:"Arial","sans-serif"'^>^<span style='color:gray'^>^&nbsp;%c_date%^</span^>^</span^>

 setlocal enableDelayedExpansion
 for /f "usebackq delims=" %%l in ("My_html_file") do (
    setlocal disableDelayedExpansion
    (echo("%%l")|findstr /i /r /c:"<span style='font-family:\"Arial\",\"sans-serif\"'><span style='color:gray'>&nbsp;.*</span></span>" >nul 2>&1&& echo ^<span style='font-family:"Arial","sans-serif"'^>^<span style='color:gray'^>^&nbsp;%c_date%^</span^>^</span^>
    (echo("%%l")|findstr /i /r /c:"<span style='font-family:\"Arial\",\"sans-serif\"'><span style='color:gray'>&nbsp;.*</span></span>" >nul 2>&1|| (echo(%%l)

 ) >> temp.html


 exit /b 0
 *****  end comment *********/

 var monthNames = [ "January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December" ];
 var now = new Date();
 var formated=  monthNames[now.getMonth()] + " " + now.getDay() +", "+ now.getFullYear();
 WScript.Echo(formated);