<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; CMD/BAT: вычисление времени]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=7898</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=7898&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «CMD/BAT: вычисление времени».]]></description>
		<lastBuildDate>Sat, 22 Dec 2012 06:33:28 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[CMD/BAT: вычисление времени]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=67331#p67331</link>
			<description><![CDATA[<p>Данный скрипт на основе двух временнЫх меток производит корректное вычисление промежутка между ними,т.е. затраченного времени (в пределах 24 часов).</p><div class="codebox"><pre><code>@================================================================
::    Name:         spendtime.bat
::    Language:     win-batch
::    CommandLine: spendtime.bat time1 time2
::    Description: Пример вычисления затраченного времени на основе двух временных меток. 
::                 В качестве разделителя разрядов временной метки - символы из набора [;:,.]
::    Author:         Аскет
@================================================================
 
@echo off
IF &quot;%*&quot;==&quot;&quot; (EXIT /B)
SET T1=%1
SET T2=%2
    ::--------------- РАЗБИЕНИЕ МЕТОК ВРЕМЕНИ НА РАЗРЯДЫ [hh,mm,ss] -------------
for /f &quot;tokens=1,2,3 delims=;:,.&quot; %%a in (&quot;%T1%&quot;) do (set h1=%%a &amp; set m1=%%b &amp; set s1=%%c)
for /f &quot;tokens=1,2,3 delims=;:,.&quot; %%a in (&quot;%T2%&quot;) do (set h2=%%a &amp; set m2=%%b &amp; set s2=%%c)
    ::--------------- СЕРИАЛИЗАЦИЯ -------------
set /a time1 = (h1*3600)+(m1*60)+(s1)
set /a time2 = (h2*3600)+(m2*60)+(s2)
    ::--------------- ВЫЧИСЛЕНИЕ -------------
set /a time3=time2-time1
    rem если время начальной точки позже конечной
if /i %time3% lss 0 set /a time3=time2+(86400-time1)
    ::--------------- ДЕСЕРИАЛИЗАЦИЯ [muchSS -&gt; hh,mm,ss] -------------
::hour
set /a H = time3/3600
set /a time3 = time3-(H*3600)
::minute
set /a M = time3/60
set /a time3=time3-(M*60)
::second
set /a S = time3
    ::--------------- ФОРМАТНАЯ КОРРЕКТИРОВКА РЕЗУЛЬТАТОВ -------------
 CALL :CheckNum %H%,H
 CALL :CheckNum %M%,M
 CALL :CheckNum %S%,S
 
set spendTime=%H%:%M%:%S%
::show result
echo ______________________________
ECHO/Spend time = [%spendTime%]
 
EXIT /B
======================
:CheckNum (varIN,varOUT)
    set /A temp_ = %1
    if &quot;%temp_:~1,1%&quot;==&quot;&quot; (SET %2=0%temp_%)
EXIT /B</code></pre></div><div class="quotebox"><blockquote><p>C:\WINDOWS\&gt;spendtime.bat 11:50:05 10:13:44<br />______________________________<br />Spend time = [22:23:39]</p></blockquote></div><div class="quotebox"><blockquote><p>&gt;spendtime.bat 3:40 5:44:02<br />______________________________<br />Spend time = [02:04:02]</p></blockquote></div>]]></description>
			<author><![CDATA[null@example.com (Аскет)]]></author>
			<pubDate>Sat, 22 Dec 2012 06:33:28 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=67331#p67331</guid>
		</item>
	</channel>
</rss>
