For example, in the system date, the value of the environment variable is .- -- atSaturday years------%date:~0,4%Indicates that the left-to- right pointer is 0-bit to the right, and then the 4-bit character is extracted from the pointer offset toMonth------%date:~5,2%indicates that the pointer is shifted from left to right by 5 bits, and then the 2-bit character is extracted from the offset, and the result isDay------%date:~8,2% 8 31
%date:~5%indicates that the pointer is shifted from left to right by 5 bits, and then all values are extractedTime-----%date:~-5%represents the pointer reverse direction offset, starting at the far right, offsetting 5 bits, and then extracting all the values from the left side of the pointer. MD F:\backup\%date:~0,4%%date:~5,2%%time:~0,2%%time:~3,2%The result: MD f:\201107231855
echo.%date:~0%date Dateecho.%time:~0%time Timeecho.%date:~0,4%year echo.%date:~5,2%echo of the moon.%date:~8,2%Day Echo.%time:~0,2%hour echo.%time:~3,2%points echo.%time:~6,2%seconds echo.%time:~9,2%in seconds pause
set/a Specifies that the string to the right of the equals sign is the evaluated numeric expression.
is to represent the calculation
Such as
@echo off
set/a xz=123+456
Echo%xz%
Pause>nul
Can output 123+456 results
Time arithmetic
@echo off:: Determine the time required for a script to complete: First take the start time and then the end time at the end:: Two time, respectively, to extract hours, minutes and seconds:: The number of hours, minute and number of seconds to operate:: Also to the 08 and 09 of the two number of operations: : Note: Set/A num=The format can only handle two digits whether the high-level is 0, if it is a multi-digit: to go to the top of all 0, to use the loop to test whether the high position is 0 or add 1 in the High Place and then:: Minus the number 1000 and so on:: Code by JM2006-9-5~Ten[email protected] Thanks Pengfei test set Time_begin=% Time:~0,-3%EchoScript start run time is%time_begin%:: Less than 10 hours ago there are spaces, to do a space operation for/F"tokens=1,2,3 delims=:"%%iinch("%time_begin%") Do(Set/A hour_b=%%I set/A munite_b=%%J Set/A second_b=%%k) Pause set Time_end=% Time:~0,-3% for/F"tokens=1,2,3 delims=:"%%iinch("%time_end%") Do(Set/A hour_e=%%I set/A munite_e=%%J Set/A second_e=%%k) Call:time_lapseEchoThe time at which the script ended runs is%time_end%EchoA total of%hour_% hours%munite_%%second_%seconds Pause>nul goto:eof:time_lapse:: Be sure to follow the seconds= = Minutes = =sequential operation of the hourif%second_e% LSS%second_b%(Set/A munite_e=%munite_e%-1Set/A second_e=%second_e%+ -) Set/A second_=%second_e%-%second_b%if%munite_e% LSS%munite_b%(Set/A hour_e=%hour_e%-1Set/A munite_e=%munite_e%+ -) Set/A munite_=%munite_e%-%munite_b%if%hour_e% LSS%hour_b%(Set/A hour_e=%hour_e%+ -) Set/A hour_=%hour_e%-%hour_b%goto:eof Another method (Code by Pengfei): @echo off:: One: ,:25.45:: Run the program's time statistics set _time_start=% Time%Set/A hour_start=%_time_start:~0,2%Set/A minute_start=1%_time_start:~3,2%- -Set/A second_start=1%_time_start:~6,2%- - Echo% Time%Echo%hour_start%Echo%minute_start%Echo%second_start%pause:: End of program time statistics set _time_end=% Time%Set/A hour_end=%_time_end:~0,2%Set/A minute_end=1%_time_end:~3,2%- -Set/A second_end=1%_time_end:~6,2%- - Echo% Time%Echo%hour_end%Echo%minute_end%Echo%second_end%Pause:: Calculates the number of secondsif%second_end% LSS%second_start%(Set/A second_end=%second_end%+ -Set/A minute_end=%minute_end%-1) Set/A second=%second_end%-%second_start%:: Count of minutesif%minute_end% LSS%minute_start%(Set/A minute_end=%minute_end%+ -Set/A hour_end=%hour_end%-1) Set/A minute=%minute_end%-%minute_start%:: Count Hoursif%hour_end% LSS%hour_start%(Set/A hour_end=%hour_end%+ -) Set/A hour=%hour_end%-%hour_start%Echo%hour%:%minute%:%second%Pause
Operation and extraction of bat time