Sunday, July 12, 2020
Mengambil Tanggal dan Waktu pada batch file.
OPSI 1:
@echo off
::Previous Windows %DATE% was "MM/DD/YYYY" -not- "DAY MM/DD/YYYY", so get it from Right to left first.
set WJ_date=%date:~-10%
set WJ_date=%WJ_date:~6,4%%WJ_date:~0,2%%WJ_date:~3,2%
echo WJ_date=%WJ_date%
:: Replace ' ' with '0' before 10am
set WJ_time=%TIME: =0%
set WJ_time=%WJ_time:~0,2%%WJ_time:~3,2%%WJ_time:~6,2%
echo WJ_time=%WJ_time%
echo.
pause
OPSI 2:
@echo off
::Previous Windows %DATE% was "MM/DD/YYYY" -not- "DAY MM/DD/YYYY" !
::for /f "tokens=1,2,3,4 delims=/ " %%a in ("%DATE%") do set MM=%%b&set DD=%%c&set YYYY=%%d
for /f "tokens=1,2,3,4 delims=/ " %%a in ('date /t') do set MM=%%b&set DD=%%c&set YYYY=%%d
set WJ_date=%YYYY%%MM%%DD%
echo WJ_date=%WJ_date%
for /f "tokens=1,2,3,4 delims=:." %%a in ("%TIME: =0%") do set hh=%%a&set nn=%%b&set ss=%%c
set WJ_time=%hh%%nn%%ss%
echo WJ_time=%WJ_time%
echo.
pause
Reff: https://www.dostips.com/DtTipsStringManipulation.php
Labels:
batch file
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment