<?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: uptime]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=14903</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14903&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «CMD/BAT: uptime».]]></description>
		<lastBuildDate>Mon, 05 Aug 2019 17:22:08 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[CMD/BAT: uptime]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135280#p135280</link>
			<description><![CDATA[<p>По мотивам темы <a href="http://forum.script-coding.com/viewtopic.php?id=14889">VBS: Время работы системы</a> написал скриптик, который почти повторяет работу unix-команды <strong>uptime</strong> -- показывает текущее время и как долго работает система.</p><p>Обсуждение в отдельной теме: <a href="http://forum.script-coding.com/viewtopic.php?id=14901">http://forum.script-coding.com/viewtopic.php?id=14901</a></p><p>Пример:</p><div class="codebox"><pre><code>
C:\&gt;uptime
 08:51:40 up 73 days, 07:57

C:\&gt;
</code></pre></div><p>Исходный код: <a href="https://github.com/ildar-shaimordanov/cmd.scripts/blob/master/uptime.bat">https://github.com/ildar-shaimordanov/c … uptime.bat</a><br />Использовалась идея, почерпнутая из этого ответа на stackoverflow <a href="https://stackoverflow.com/a/11128674/3627676">https://stackoverflow.com/a/11128674/3627676</a></p><div class="codebox"><pre><code>
@echo off

:: ========================================================================

setlocal

set &quot;uptime_boot=&quot;
set &quot;uptime_curr=&quot;

for /f &quot;tokens=1,* delims==&quot; %%a in ( &#039;
	wmic OS GET LastBootUpTime^,LocalDateTime /VALUE
&#039; ) do if /i &quot;%%~a&quot; == &quot;LastBootUpTime&quot; (
	call :get_ts &quot;%%~b&quot; uptime_boot
) else if /i &quot;%%~a&quot; == &quot;LocalDateTime&quot; (
	call :get_ts &quot;%%~b&quot; uptime_curr
)

set /a &quot;uptime_diff=uptime_curr-uptime_boot&quot;

call :get_datetime diff
call :get_datetime curr

echo: %uptime_curr_hh%:%uptime_curr_mm%:%uptime_curr_ss% up %uptime_diff_dd% days, %uptime_diff_hh%:%uptime_diff_mm%

goto :EOF

:: ========================================================================

:get_datetime
set /a &quot;uptime_%~1_ss=uptime_%~1 %% 60&quot;
set /a &quot;uptime_%~1_mm=uptime_%~1 / 60 %% 60&quot;
set /a &quot;uptime_%~1_hh=uptime_%~1 / 60 / 60 %% 24&quot;
set /a &quot;uptime_%~1_dd=uptime_%~1 / 60 / 60 / 24&quot;

call set &quot;uptime_%~1_ss=0%%uptime_%~1_ss%%&quot;
call set &quot;uptime_%~1_mm=0%%uptime_%~1_mm%%&quot;
call set &quot;uptime_%~1_hh=0%%uptime_%~1_hh%%&quot;

call set &quot;uptime_%~1_ss=%%uptime_%~1_ss:~-2%%&quot;
call set &quot;uptime_%~1_mm=%%uptime_%~1_mm:~-2%%&quot;
call set &quot;uptime_%~1_hh=%%uptime_%~1_hh:~-2%%&quot;

goto :EOF

:: ========================================================================

:: Borowed from https://stackoverflow.com/a/11128674/3627676

:: Convert date/time from YYYYMMDDhhmmss.SSSSSS+zzz to Unix timestamp

:: 20190523222121.762088+180
:: 20190801180759.901000+180
::           1         2
:: 0123456789012345678901234

:: Get the timestamp in UTC
:get_ts_utc

:: Get the timestamp in local time
:get_ts
setlocal

set &quot;ts=%~1&quot;

set /a &quot;yy=10000%ts:~0,4% %% 10000, mm=100%ts:~4,2% %% 100, dd=100%ts:~6,2% %% 100&quot;
set /a &quot;dd=dd-2472663+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4&quot;

::set /a ss=(((1%ts:~8,2%*60)+1%ts:~10,2%)*60)+1%ts:~12,2%-366100-%ts:~21,1%((1%ts:~22,3%*60)-60000)
set /a &quot;ss=(((1%ts:~8,2%*60)+1%ts:~10,2%)*60)+1%ts:~12,2%-366100&quot;
if &quot;%~0&quot; == &quot;:get_ts_utc&quot; set /a &quot;ss-=%ts:~21,1%((1%ts:~22,3%*60)-60000)&quot;

set /a ss+=dd*86400

endlocal &amp; if &quot;%~2&quot; neq &quot;&quot; (set %~2=%ss%) else echo %ss%
goto :EOF

:: ========================================================================

:: EOF
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Mon, 05 Aug 2019 17:22:08 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135280#p135280</guid>
		</item>
	</channel>
</rss>
