วิธีหา วันที่-เวลา ปัจจุบัน ในรูปแบบ YYYY-MM-DD HH:MM:SS.sss ด้วย windows batch file


batch file: gettime.bat
/*--------------------------------------------------------------------------------------*/
@echo off
for /F "usebackq tokens=1,2 delims==" %%a in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%a.'=='.LocalDateTime.' set ldt=%%b
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
echo current datetime = [%ldt%]

/*--------------------------------------------------------------------------------------*/

output:
/*----------------------------------------------*/
C:\>gettime.bat
current datetime = [2013-04-15 18:38:53.199]

/*----------------------------------------------*/

อ้างอิง:
* Windows Batch Scripting
* For - Looping commands
* WMIC - Windows Management
* Using command redirection operators

--