I was working to a script that I needed to read the time from the system with seconds but not milliseconds. I noticed that some computers have a different region settings that did caused me a few problems like the date from one computer is shown as 01/01/2020
, the other one with 01.01.2020
using the command %date%
etc.
Same thing if I use the command %time%
, some computers is shown a time like 12:13:14,15
, some like 12:13:14.16
.
Now, to solve this problem I have to create a variable to read the separator symbol and output the correct one. For the command date It was simple.
For time I have this command:
FOR /F "tokens=3 delims=0123456789" %%A IN ('echo %time%') DO set timeSeparatorSymbol=%%A
If the computer have the symbol for separator for milliseconds as .
then the output is:
timeSeparatorSymbol=.
Which is good.
If the computer have the symbol for separator for milliseconds as ,
then the output is:
timeSeparatorSymbol=
As you see, the variable is not created and I'm struggling figure it out why the comma doesn't accept it as a variable.
I need this for the following script to works to all computers no matter the regional settings:
for /f "tokens=3 delims=:%timeSeparatorSymbol%" %%A in ('echo %time%') do set second=%%A
Thank you in advance.