Last active
December 30, 2023 00:15
-
-
Save robinrm/d2807a25a7910a4775b777f7596c45f3 to your computer and use it in GitHub Desktop.
Local Date Time Generator Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:initial_Section | |
::set async mode | |
setlocal EnableDelayedExpansion | |
::var | |
::server template location | |
set templates="C:\_templates\_ldt" | |
::caller | |
::set ldt= | |
::UI | |
set title=Local Date Time Generator | |
set cmd_width=50 | |
set cmd_height=5 | |
set color_green=0a | |
:: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
:: var init done | |
::set UI Information | |
mode con lines=%cmd_height% cols=%cmd_width% | |
powershell -command "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%cmd_width%;$B.height=9999;$W.buffersize=$B;}" | |
title %title% | |
color %color_green% | |
::del old ldt | |
if exist "%templates:~1,-1%\*.ini" ( | |
del "%templates:~1,-1%\*.ini" | |
echo deleted old ldt file | |
) | |
:start_Section | |
::WMIC to retrieve date and time | |
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j | |
set ldt=%ldt:~0,4%.%ldt:~4,2%.%ldt:~6,2%_%ldt:~8,2%.%ldt:~10,2%.%ldt:~12,2% | |
set check_s=%ldt:~18,1% | |
::check if ldt equals 0 or 5s at last position | |
if %check_s% equ 0 ( | |
goto process_ldt | |
) else ( | |
if %check_s% equ 5 ( | |
goto process_ldt | |
) else ( | |
goto start_Section | |
) | |
) | |
:process_ldt | |
cls | |
if not exist "%templates:~1,-1%\*.ini" ( | |
::create new file | |
echo created new file | |
copy nul "%templates:~1,-1%\%ldt%.ini" | |
) else ( | |
::rename file | |
move "%templates:~1,-1%\*.ini" "%templates:~1,-1%\%ldt%.ini" | |
) | |
echo ldt new: %ldt% | |
timeout /T 1 /NOBREAK >nul | |
goto start_Section | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment