下面的文件很好地满足了我的大部分要求。但是,时间格式似乎不是我想要的。无论计算机上的时间设置如何,我都希望始终获取时间ISO8601
(例如 20150930T012823Z)。该怎么做?
@ECHO off
:: Check the Windows version
IF NOT "%OS%"=="Windows_NT" GOTO:OS
SETLOCAL
:: Initialize variable
SET Error=0
:: Check the command line arguments
IF "%~1"=="" GOTO Syntax
IF "%~2"=="" GOTO Syntax
IF "%~3"=="" GOTO Syntax
set v_barrier=%1
set v_rtspcommand=%2
set v_AccessCard=%3
set v_Pictures=%4
IF "%~4" =="" set v_Pictures=%PUBLIC%\Pictures
:: Keep variables local
SETLOCAL ENABLEDELAYEDEXPANSION
:: Checking if ffmpeg is properly installed as per setting in PATH
IF NOT EXIST "%ffmpeg%\ffmpeg.exe" (
ECHO ffmpeg.exe could not be found in %ffmpeg%
GOTO:EOF
)
VERIFY OTHER 2>nul
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 ECHO Unable to enable extensions
if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
for /f "tokens=2-4 delims=(-)" %%a in ('echo:^|date') do (
for /f "tokens=%toks% delims=.-/ " %%i in ('date/t') do (
set '%%a'=%%i
set '%%b'=%%j
set '%%c'=%%k))
if %'yy'% LSS 100 set 'yy'=20%'yy'%
set Today=%'yy'%-%'mm'%-%'dd'%
ENDLOCAL & SET v_year=%'yy'%& SET v_month=%'mm'%& SET v_day=%'dd'%& SET /a last_year=%'yy'%-1
:: Time in ISO 8601 24-hour format
VERIFY OTHER 2>nul
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 ECHO Unable to enable extensions
for /f "tokens=1-4 delims=:,.-/ " %%i in ('echo %time%') do (
set 'hh'=%%i
set 'mm'=%%j
set 'ss'=%%k
set 'ff'=%%l)
ENDLOCAL & SET v_hour=%'hh'%& SET v_minute=%'mm'%& SET v_second=%'ss'%& SET v_fraction=%'ff'%
:: Barrier = I1-I9 (for Ingress) or E1-E9 (for Egress)
set output_path=%v_Pictures%\%v_barrier%%v_year%%v_month%
if not exist %output_path% mkdir %output_path%
:: Delete folder that is one year old
if exist %v_Pictures%\%v_barrier%%last_year%%v_month% rmdir /s /q %v_Pictures%\%v_barrier%%last_year%%v_month%
:: Ingress / Egress parrier:
IF %v_barrier% GEQ I0 IF %v_barrier% LEQ I99 GOTO:NEXT
IF %v_barrier% GEQ E0 IF %v_barrier% LEQ E99 GOTO:NEXT
GOTO:SYNTAX
:NEXT
set timestring=%v_barrier%%v_year%%v_month%%V_Day%T%v_hour%""%v_minute%%v_second%Z%v_AccessCard%
START "" "%ffmpeg%\ffmpeg" -rtsp_transport tcp -y -i %v_rtspcommand% -nostats -loglevel 0 -pix_fmt yuv420p -f image2 -
vframes 1 -ss 00:00:01.500 -s 1920x1200 %output_path%\%timestring%.jpg
GOTO:EOF
:SYNTAX
ECHO FFMPEGPIS.BAT - FFMPEG Photo Imaging System ver 1.1
ECHO Usage: FFMPEGPIS [ Ix or Ex, rtsp, Access Card, Picture folder ]
ECHO.
ECHO Where: "Ix or Ex" I = Ingress followed by integer 0-9
ECHO E = Egress followed by integer 0-9
ECHO.
ECHO "rtsp" command from camera (rtsp)
ECHO "Access Card" Short Range Access Card
ECHO "Picture Folder" If blank, %PUBLIC%\Pictures will be used
:OS
IF NOT "%OS%"=="Windows_NT" ECHO OS needs to be Windows NT 4 or higher
:EOF
答案1
这是一个与地区无关的获取日期和时间的方法。
@echo off
for /F "usebackq tokens=1,2 delims==" %%i in (
`wmic os get LocalDateTime /VALUE 2^>NUL`
) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
echo Local date is [%ldt%]
输出:
Local date is [2015-10-02 20:10:00.000]
只需根据需要编辑变量即可。您可以获得更多变化这里