How get data/time independent from localization

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: How get data/time independent from localization

#46 Post by npocmaka_ » 08 Nov 2013 07:54

dbenham wrote:@npocmaka - As posted, your code failed.
I don't see any tabs in the output, so I got the code to "work" by using DELIMS=<colon><space>

However, I should think most scenarios require a numeric value for the month, (and possibly for the day of week). I suppose a simple translation table could be used. But does ROBOCOPY always use English for the day of week and month abbreviations? If not, then I don't see how this could be considered locale independent.

Dave Benham


Thanks.Fixed.I don't know about localizations :? (only date/time/currency settings are localized in bulgarian versions of Windows ) . May be somebody with german/spanish/italian.. version can enlight the topic.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How get data/time independent from localization

#47 Post by Aacini » 08 Nov 2013 10:58

And ROBOCOPY is NOT included in Win XP...

EDIT: Tested on Windows 8 Spanish version, the original robocopy-based Batch program show:

Code: Select all

C:> test
Day of the week:
Day of the month :
Month :
hour :
minutes :
seconds :
year :

C:> robocopy /l * \ \ /ns /nc /ndl /nfl /np /njh /XF * /XD *

------------------------------------------------------------------------------

               Total   Copiado   OmitidoNo coincidencia     ERROR    Extras
Directorios:        16         0        15         0         0         0
 Archivos:         7         0         7         0         0         0
    Bytes:   3.152 g         0   3.152 g         0         0         0
    Veces:   0:00:00   0:00:00                       0:00:00   0:00:00
   Finalizado: viernes, 8 de noviembre de 2013 11:03:13 a. m.



I then modified "skip=10" by "skip=8" and get:

Code: Select all

C:> test
Day of the week: viernes,
Day of the month : de
Month : 8
hour : noviembre
minutes : de
seconds : 2013
year : 11


Antonio

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: How get data/time independent from localization

#48 Post by carlos » 08 Nov 2013 11:56

Here my last version of getdate using makecab:
http://www.dostips.com/forum/viewtopic.php?p=29758#p29758

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: How get data/time independent from localization

#49 Post by npocmaka_ » 07 Sep 2014 12:25

This cannot get the year and day of the week.It's comparatively slow , also creates a temp file and is based on the time stamps that logman puts on its log files.Requires admin permissions.Will work everything from XP and above.Probably will be never used by anybody - including me - but is one more way...

Code: Select all

@echo off
setlocal
del /q /f %temp%\timestampfile_* >nul 2>&1

Logman.exe stop ts-CPU 1>nul 2>&1
Logman.exe delete ts-CPU 1>nul 2>&1

Logman.exe create counter ts-CPU  -sc 2 -v mmddhhmm -max 250 -c "\Processor(_Total)\%% Processor Time" -o %temp%\timestampfile_ >nul
Logman.exe start ts-CPU 1>nul 2>&1

Logman.exe stop ts-CPU >nul 2>&1
Logman.exe delete ts-CPU >nul 2>&1
for /f "tokens=2 delims=_." %%t in  ('dir /b %temp%\timestampfile_*^&del /q/f %temp%\timestampfile_*') do set timestamp=%%t

echo %timestamp%
echo MM: %timestamp:~0,2%
echo dd: %timestamp:~2,2%
echo hh: %timestamp:~4,2%
echo mm: %timestamp:~6,2%

endlocal
exit /b 0

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Batch Script to locate specified path on FTP server

#50 Post by Squashman » 10 Jul 2015 11:05

Anybody know if TYPEPERF outputs the same date and time format regardless of regional date/time settings?

Code: Select all

H:\>typeperf "\processor(_Total)\% Processor Time" -SC 1

"(PDH-CSV 4.0)","\\WI5101AC727734\processor(_Total)\% Processor Time"
"07/10/2015 12:05:18.189","31.434988"

The command completed successfully.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#51 Post by aGerman » 10 Jul 2015 12:06

The time format is the same but the object name is language dependent.

Code: Select all

C:\>typeperf "\Prozessor(_Total)\Prozessorzeit (%)"  -SC 1

"(PDH-CSV 4.0)","\\STEFFEN-PC\Prozessor(_Total)\Prozessorzeit (%)"
"07/10/2015 19:57:49.460","3.845703"

Der Befehl wurde erfolgreich ausgeführt.

C:\>


Regards
aGerman

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: How get data/time independent from localization

#52 Post by Squashman » 10 Jul 2015 12:12

But we could get around that by using TYPEPERF /Q to get a valid counter.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#53 Post by aGerman » 10 Jul 2015 12:20

How :? What string would you look for?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: How get data/time independent from localization

#54 Post by Ed Dyreen » 10 Jul 2015 12:47

first I get the language info from registry

Code: Select all

(%regKeyRead_% $,"HKLM\SYSTEM\CurrentControlSet\Control\Nls\Language","InstallLanguage")3>nul 2>&3>&3&&(
   %forQ_% ("§region.!$!") do set §lang=!%%~?!
)
then perform a lookup to get the country

Code: Select all

for %%? in (

   "§region"

) do (
   set "%%~?.0405=cz" &set "%%~?.0414=no" &set "%%~?.080C=be"
   set "%%~?.0406=dk" &set "%%~?.0415=pl" &set "%%~?.0813=be"
   set "%%~?.0407=gr" &set "%%~?.0416=br" &set "%%~?.0816=po"
   set "%%~?.0409=us" &set "%%~?.0419=ru" &set "%%~?.0C0C=cf"
   set "%%~?.040A=sp" &set "%%~?.041A=yu" &set "%%~?.1009=us"
   set "%%~?.040B=su" &set "%%~?.041B=sl" &set "%%~?.100C=sf"
   set "%%~?.040C=fr" &set "%%~?.041D=sv" &set "%%~?.0409=dv"
   set "%%~?.040E=hu" &set "%%~?.0807=sg" &set "%%~?.040A=sp"
   set "%%~?.040F=us" &set "%%~?.0809=uk" &set "%%~?.0C0C=cf"
   set "%%~?.0410=it" &set "%%~?.080A=la" &set "%%~?.0409=us"
   set "%%~?.0413=nl"
)
And then create the variable for supported languages.

Code: Select all

%forQ_% ( be, nl ) do if /I "!§lang!" == "%%~?" set "$cmd=Percentage processortijd"
%forQ_% ( us, uk ) do if /I "!§lang!" == "%%~?" set "$cmd=Processor Time"
Now I can use typeperf

Code: Select all

'typeperf.EXE "\Proces(*)\!$cmd!" -SC 1'
Squashman wrote:But we could get around that by using TYPEPERF /Q to get a valid counter.
When using the /Q option this is what I get

Code: Select all

C:\profSys\ADMIN>typeperf /Q Processor
\Processor(*)\Percentage processortijd
...
I see the text I am after, but will I be sure that 'Percentage processortijd' will always be the first result of typeperf /Q, and will object 'Processor' always be named 'Processor' ?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: How get data/time independent from localization

#55 Post by Squashman » 10 Jul 2015 13:14

I guess I assumed that the first counter it output would be valid and would have counters.

Code: Select all

FOR /F "delims=" %%G ('typeperf /q') DO (
     set tp=%%G
     goto BREAK
)
:BREAK

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#56 Post by aGerman » 10 Jul 2015 13:17

and will object 'Processor' always be named 'Processor' ?

Nope.

Code: Select all

C:\>typeperf /Q Processor


Fehler:
Das angegebene Objekt wurde nicht auf dem Computer gefunden.


C:\>typeperf /Q Prozessor
\Prozessor(*)\Prozessorzeit (%)
\Prozessor(*)\Benutzerzeit (%)
\Prozessor(*)\Privilegierte Zeit (%)
\Prozessor(*)\Interrupts/s
\Prozessor(*)\DPC-Zeit (%)
\Prozessor(*)\Interruptzeit (%)
\Prozessor(*)\DPCs in Warteschlange/s
\Prozessor(*)\DPC-Rate
\Prozessor(*)\Leerlaufzeit (%)
\Prozessor(*)\% C1-Zeit
\Prozessor(*)\% C2-Zeit
\Prozessor(*)\% C3-Zeit
\Prozessor(*)\C1-Übergänge/s
\Prozessor(*)\C2-Übergänge/s
\Prozessor(*)\C3-Übergänge/s

Der Befehl wurde erfolgreich ausgeführt.

C:\>

For the same reason your approach won't work for me. There is no "\Proces(*)" root object.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: How get data/time independent from localization

#57 Post by Squashman » 10 Jul 2015 14:41

Well I thought we had another way to get the date and time without regional dependencies. :evil:

I think there is a few other posts in this thread about using the registry. I have used this one in the past.

Code: Select all

@echo off
::Reference http://forums.techguy.org/dos-other/976906-batch-script-delete-oldest-folders.html#post7784490
Set _Date=%Date%
If "%_Date%A" LSS "A" (Set _NumTok=1-3) Else (Set _NumTok=2-4)
Set _TDYM=

For /F "Tokens=2*" %%A In ('Reg Query "HKCU\Control Panel\International" /v iDate') Do Set _iDate=%%B
For /F "Tokens=2*" %%A In ('Reg Query "HKCU\Control Panel\International" /v sDate') Do Set _sDate=%%B
If %_iDate%==0 For /F "Tokens=%_NumTok% Delims=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%D%%B%%C
If %_iDate%==1 For /F "Tokens=%_NumTok% Delims=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%D%%C%%B
If %_iDate%==2 For /F "Tokens=%_NumTok% Delims=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%B%%C%%D
If "%_fdate:~7,1%"=="" For /F "Tokens=3 skip=3" %%I In ('Reg Query "HKCU\Control Panel\International\Calendars\TwoDigitYearMax" /V 1 2^>Nul') Do Set _TDYM=%%I
If Defined _TDYM (Set _MaxY=%_TDYM:~2%&Set _Cent=%_TDYM:~0,2%) Else (Set _MaxY=29&Set _Cent=20)
Set /A _Cm1=_Cent-1
If "%_fdate:~7,1%"=="" If %_fdate:~0,2% LEQ %_MaxY% (Set _fdate=%_Cent%%_fdate%) Else (Set _fdate=%_Cm1%%_fdate%)

echo %_fdate%
pause

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How get data/time independent from localization

#58 Post by foxidrive » 10 Jul 2015 20:58

Squashman wrote:Well I thought we had another way to get the date and time without regional dependencies. :evil:


There seem to be a number of alternative entries for typeperf.

Code: Select all

typeperf -q|find /i "time"|more


d:\>typeperf "\ICMP\Received Timestamp/sec" -sc 1

"(PDH-CSV 4.0)","\\MEI7\ICMP\Received Timestamp/sec"
"07/11/2015 12:55:05.197","0.000000"



Just an idle thought: does Windows in another language respond to an English command?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#59 Post by aGerman » 11 Jul 2015 06:23

does Windows in another language respond to an English command?

In that case it's neither the command and its options nor the format of the output that restricts you. The object names are language dependent. Only a few of them seem to (maybe) have always English names.

Code: Select all

C:\>typeperf -q|find /i "time"|more
\Windows Media Player Metadata(*)\Normalization Time (ms)
\Windows Media Player Metadata(*)\Commit Time (ms)
\Windows Media Player Metadata(*)\Reorganize Time (ms)
\Windows Media Player Metadata(*)\Art Extraction Time (ms)
\Windows Media Player Metadata(*)\Property Extraction Time (ms)
\Windows Media Player Metadata(*)\URL Classification Time (ms)
\Windows Media Player Metadata(*)\AFTS Execution Time (ms)
\Windows Media Player Metadata(*)\Timestamp Directory Hit Count
\MSDTC Bridge 3.0.0.0\Average participant prepare response time
\MSDTC Bridge 3.0.0.0\Average participant commit response time


C:\>typeperf "\ICMP\Empfangene Zeiteintragsmeldungen/s" -sc 1

"(PDH-CSV 4.0)","\\STEFFEN-PC\ICMP\Empfangene Zeiteintragsmeldungen/s"
"07/11/2015 14:21:49.820","0.000000"

Der Befehl wurde erfolgreich ausgeführt.

C:\>

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How get data/time independent from localization

#60 Post by foxidrive » 11 Jul 2015 06:34

aGerman wrote:
does Windows in another language respond to an English command?

In that case it's neither the command and its options nor the format of the output that restricts you. The object names are language dependent. Only a few of them seem to (maybe) have always English names.


Thanks aGerman.

If you execute this command then you get an error I guess? That's what I was wondering, if Windows can respond to more than one language.

Code: Select all

typeperf "\ICMP\Received Timestamp/sec" -sc 1

Post Reply