Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for sorttime.bat

(view source code of sorttime.bat as plain text)

  1. @ECHO OFF
  2. :: SortTime, Version 2.10 for Windows NT
  3. :: Save time and "sorted" time in environment variables.
  4. ::
  5. :: This batch file will always display the same results,
  6. :: independent of "International" settings.
  7. :: This batch file uses REG.EXE from the NT Resource Kit
  8. :: to read the "International" settings from the registry.
  9. ::
  10. :: Written by Rob van der Woude
  11. :: http://www.robvanderwoude.com
  12.  
  13. FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET TIME=%%A
  14. :: Delims is a TAB followed by a space
  15. FOR /F "TOKENS=2* DELIMS=	 " %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International\iTime"') DO SET iTime=%%B
  16. FOR /F "TOKENS=2* DELIMS=	 " %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International\sTime"') DO SET sTime=%%B
  17. IF %iTime%==1 GOTO Sort
  18. SET AMPMTIME=%TIME%
  19. FOR /F "TOKENS=1,2* DELIMS=%sTime% " %%A IN ('ECHO %TIME%') DO (
  20. 	SET HOUR=%%A
  21. 	SET MINS=%%B
  22. )
  23. SET AMPM=%MINS:~2,1%
  24. SET MINS=%MINS:~0,2%
  25. IF %HOUR% LSS 12 IF /I %AMPM%==P SET /A HOUR=%HOUR%+12
  26. IF %HOUR% LSS 10 IF /I %AMPM%==A SET HOUR=0%HOUR%
  27. IF %HOUR% EQU 12 IF /I %AMPM%==A SET HOUR=00
  28. SET TIME=%HOUR%%sTime%%MINS%
  29.  
  30. :Sort
  31. FOR /F "TOKENS=1,2* DELIMS=%sTime% " %%A IN ('ECHO %TIME%') DO SET SORTTIME=%%A%%B
  32. ECHO It's %TIME% now
  33. :: Thanks for Holger Stein who mailed me this correction (add leading zero):
  34. IF %SORTTIME% LSS 1000 SET SORTTIME=0%SORTTIME%
  35. ECHO For sorting purposes: %SORTTIME%
  36.  

page last uploaded: 2017-08-21, 14:26